VS 2010 Use SyncLock On Function On Each Thread?
Sep 8, 2011
Ok so I coded this app that generates a number/word and it will upload to my database. Speed wasn't the issue when my db was under 1million entry. Now that I got about 100million entry it takes a few mins to upload.I worked with threading before but now I want all my threads to access this function that will give them a string. Now here is the problem, if 2 or more thread access the function at the same time, it will crash.How can I by pass that?I read about SyncLock. Can I use SyncLock on my function on each thread?
View 1 Replies
ADVERTISEMENT
Nov 13, 2009
I have a dictionary object (let's call it _do) I am using to cache some values for use in a multi-threaded program. I have a single controlling parent thread, with a timer function _doTimer() which can kick off child threads with a new instance of class MyThreadObject in each. My parent thread has _do as a property and with each time _doTimer() gets called, it may or may not repopulate _do depending on cacheflag settings. I pass a reference to _do to each instance of MyThreadObject and those threads at some point read the values of _do but DO NOT write to it.
What I want is to ensure that the child threads do not try and read _do whilst the parent thread is writing to it. Same thing but very slightly different -> I also don't want the parent thread to write to _do whilst the child threads are reading from it. However there is no problem with 1 child thread reading the values of _do at the same time as another child thread is reading the values - so ideally I do not want each child thread to completely lock out read access, only locking out Write access.. The code is roughly like this:
[Code]....
View 3 Replies
Mar 30, 2012
I created a STRING SEARCH function in C/C++ - and I'm trying to use it in a multi-threaded situation in VB. I started this problem in a thread in the C/C++ section of the forum - here [URL] my last post shows me getting this error trying to call the function. Ran the code - got to that point - and in the immediate window I did
[Code]...
View 4 Replies
Aug 13, 2010
In one application, I need use 4 simultaneous threads.When the threads finished, I need to update the text of a TextBox.So, I create 4 Textbox, and I wanna the threads change the text to FINISHED.Each thread change one distinct TB.I use this "example"
Dim Terminados As Integer = 0
Private Sub frmEnviarMensagem_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Timer1.Start()
[code]....
The problem is, I have an error in the red lines.The error is: INVALIDOPERATIONEXCEPTION "Cross-Thread operation not valid: Control tbPlaca1 Accessed from a thread other than the thread it was created on."I don't use cross threading. Each TB only was accessed for the correspondent thread, and for the "main program".
View 3 Replies
Dec 4, 2008
A non-UI thread in my prog needs to obtain data from a UI listview control. To prevent cross-thread errors I use the following, but it freezes the prog (probably because the "Else" part is never called).What am I doing wrong?
[Code]...
View 2 Replies
May 7, 2011
I have a very hard time to run a function in it's own thread.
I would like to call this function with some data like[code]...
\
I dont understand how I can pass data to the function if I want to run it as it's own thread.
View 6 Replies
Nov 6, 2009
I have a couple of threads running. One is a trigger which picks up a system event, the other processes stuff. When the trigger picks up the event I want it to notify the processor thread to do stuff. The threads are both started within the same class and can access the thread-object of the other thread. How do I set up the function call though?
View 10 Replies
May 3, 2010
How can we declare a thread for function in vb.net Actually i have to declare nine functions which takes the oracle command as input parameter and return multiple values ( return types will includes datatime,string and a datatable ) . So to return multiple values from function , i have declared a structure and returning as a structure.but now the issue is !!! : As the thread is a void type and doesnt accept return types which function returns ... Now how can i declare thread for a function which accepts and returns arguments.
Public
Shared
Function Function1(ByVal
[code]....
View 1 Replies
Feb 11, 2011
i have these 2 functions that search for any .jpg files starting from a given path the algorithm works, it's just that it freezes up the gui at times this is why i wish to know how to implement it through a new thread or a backgroundworker maybe.[code]
View 2 Replies
Apr 16, 2012
I am trying to create a new thread using an anonymous function but I keep getting errors. Here is my code:
New Thread(Function()
// Do something here
End Function).Start
Here are the errors I get:
New - Syntax Error
End Function - 'End Function' must be preceded by a matching 'Function'.
View 3 Replies
Apr 29, 2011
I have this code:
Public Sub Submit(
ByVal reasonId As Integer,
ByVal email As String,
ByVal message As String
)
'[Argument validation code here]
EmailController.sendMail(reasonId, email, message)
End Sub
I want to spin this off in a new thread so Submit() returns right after creating and start the thread.In C#, I could do something like this:new Thread(() => { EmailController.sendMail(reasonId, email, message)}).Start();
View 1 Replies
Mar 31, 2011
when trying to run a function in a separate thread, my reason for trying this is because since the application is only run on one thread, the GUI hangs when the function is called.[code]In this code, the Print screen Button is pressed and the function HookCallBack is called.The problem is that the function has variables that need to be passed and returned, and while searching, i found a website that had an answer for this, and it required the function to be put in a class, and then it could be run on a separate thread while still passing all the variables needed.url...But the code cannot be placed in a class without giving errors and it seems to me like i did something wrong. The code is meant to be used in a form and not a class.My question is, how would i go about running the HookCallBack Function in a Separate thread?
View 5 Replies
Feb 3, 2010
I am running a query in a thread but I can't figure out how to get the result back to the calling function. I am doing something like this:
Threading.ThreadPool.QueueUserWorkItem(AddressOf RunThread, "some query string")
Private Function RunThread(ByVal stateInfo As Object) As String
Dim myQuery As String = stateInfo.ToString
[Code]....
View 3 Replies
Nov 3, 2011
This is the error message I am getting:
"Cross-thread operation not valid: Control 'Panel1' accessed from a thread other than the thread it was created on." The reason I am getting this error is because I am opening up a new form and then calling these three things:
Panel1.Show()
Label1.Show()
Label2.Show()
why I get this error message because it doesn't occur normally if I open Form2 after closing Form1, it only occurs when I open Form2 after closing Form4.
View 4 Replies
Jul 21, 2009
I have done a program using vb2005 to display reading from my microcontroller bs2 board but have encountered some problems. My code are as follows.
Dim Stop_Rx As Boolean
Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
SerialPort1.Open()
[code]....
I've encounter an error which is, (Cross-thread operation not valid: Control 'txt1' accessed from a thread other than the thread it was created on.)
View 7 Replies
Jun 21, 2012
When my client try to connect to server I'm getting this error : Cross-thread operation not valid: Control 'l_users' accessed from a thread other than the thread it was created on.
Private Sub _socketManager_onConnectionAccept(ByVal SocketID As String) Handles _socketManager.onConnectionAccept
l_Users.Items.Add(SocketID)
End Sub
View 3 Replies
Feb 17, 2012
Would anyone be able to help me here please. I'm fairly new to VB.net and threading so im just trying to figure out what is happening.When I debug this I am getting the error thread operation not valid: Control 'ProgressBar1' accessed from a thread other than the thread it was created on.
I'm a little lost as to why the error is occuring or how to fix it. I've had to put the progress bar in a separate thread otherwise the GUI crashes
[Code]...
View 2 Replies
Sep 2, 2010
My understanding is that thread.join will suspend the execution of code on the calling thread until the spawned thread finishes or is aborted...
With that in mind, I tried this:
For i = 1 to 50
threads = New Thread(AddressOf test)
threads.IsBackground = True
threads.SetApartmentState(ApartmentState.STA)
[CODE]...
However, the rest of the code runs when the loop finishes, not waiting for all the spawned threads to finish. Since the rest of the code needs the threads to finish (otherwise the rest will error).
View 4 Replies
Jun 6, 2010
I have written an application that loads a form - frmCad as well as AutoCad. It does this via a class which detects when AutoCad quits.
Friend Class CadApp Private WithEvents AppObject As AcadApplication... Private Sub AppObject_BeginQuit(ByRef Cancel As Boolean) Handles AppObject.BeginQuit RaiseEvent Quit() End SubEnd Class
My main class loads frmCad as well as CadApp.
Public Class Cad Private WithEvents frmCad As CadForm Private WithEvents app As CadApp... Public Sub ShowForm() If frmCad Is Nothing Then frmCad = New CadForm frmCad.Visible = True End Sub... Private Sub app_Quit() Handles app.Quit frmCad.Dispose() frmCad = Nothing .... End Sub
When I debug the program, it stops at frmCad.Dispose()The program continues to execute, but all the code after it fails to work.Looking more carefully I get an error message which contains:-Cross-thread operation not valid: Control 'Autocad' accessed from a thread other than the thread it was created on.
View 4 Replies
Feb 9, 2011
My error:Cross-thread operation not valid: Control 'label2' accessed from a thread other than the thread it was created on. I want to be able to give my Public RunBot() sub access to edit Labels, buttons, etc without an error.
[Code]...
View 8 Replies
Apr 1, 2010
I'm getting the 'System.InvalidOperationException' error on acccessing a thread from other than where it was created. My code is:
'Required by the Windows Form Designer
Public components As System.ComponentModel.IContainer ' changed from private
[code]....
View 3 Replies
Jun 6, 2009
My problem is Cross-thread operation not valid: Control 'statusHO' accessed from a thread other than the thread it was created on.
System.InvalidOperationException was unhandled
Message="Cross-thread operation not valid: Control 'statusHO' accessed from a thread other than the thread it was created on."
Source="System.Windows.Forms"
StackTrace:
[Code]...
i used it and it works fine then. but as it is mentioned its not a good practice to use it. So what should i do? is it ok if i use this as i am not able to use correct practice. Mine application is not for enterprise purpose. its just my class project, and it works fine even if i put application working in background. System works ok. I dont know how to correct this error.As i dont have that much knowlege of threads.
So please guide me how to fix this in correct way otherwise i am force to go for bad programming practice
Please refer to Windows Mobile Developer Center > Smart Device Development Forums > Windows Mobile Development > Appendtext not working for all my code details
View 1 Replies
Jan 5, 2012
Im having a problem understanding if accessing httpcontext inside a shared function, without passing in the httpcontext as a parameter is thread safe?
Are the 2 functions in the util class equally thread safe?
Class foo
Sub main()
Dim qs1 = util.getQS(HttpContext.Current)
[Code]....
View 2 Replies
Feb 27, 2012
Updating the TextBox from a Thread that calls a function within a Class does not work. I'm trying to get this to work in a DLL (but I tried without as well). The DLL is accepting an Object as an argument[code]....
View 1 Replies
Oct 4, 2010
What is the Invoke syntax to marshall data from a background thread receive callback method to a function on the UI Thread?(Form1).
Public Class Form1
MyDelegate = New DisplayData(AddressOf DisplayData)
Private Sub Form1_Load()
MyDelegate = New DisplayData(AddressOf DisplayData)
[code]....
View 12 Replies
Mar 21, 2011
when I try to perform a cross thread call to fill a text box with messages with the following code I have no problems:
Delegate Sub SetTextCallback(ByVal [text] As String)
Public Sub SetStatusBox(ByVal [text] As String)
If Me.statusBox.InvokeRequired Then
[code]....
However, I am having problems when I use the following code to do a cross thread call to close a form. The form just hangs there.
Public Delegate Sub setFormClosing(ByVal ctrl As Control)
Private Sub closeForm(ByVal ctrl As Control)
If Me.InvokeRequired Then
[code]....
View 7 Replies
Mar 4, 2012
I'm calling a class function in a thread function. I'm using invoke method to send a value to a progressbar in the main form and I don't know how to do that in an other class function called by the thread function.
My goal is to send a value to a progressbar to the main form from the thread function and even from the function called by the thread function.
My code:
' Invoke sub
Public Sub UpdPgEvent(ByVal value As Integer)
Me.pgFindEvent.Value = value
[Code]....
View 1 Replies
Aug 4, 2009
Cross-thread operation not valid: Control 'lv1' accessed from a thread other than the thread it was created on.
Dim lvi As ListViewItem
For Each lvi In lv1.Items
[code]....
View 1 Replies
Jan 15, 2012
I've been reading up on asynchronous function / web pages for ASP.NET 3.5 (we're not using v4 yet) but the ones I've seen all focus on performing a background task but then still coming back to finish up and send the response, after the task is complete.
What I want to do is simply kick off the background task (in this case a call to a web service) but then return a response to the browser immediately - ie. without waiting for the asynchronous task to complete. I don't even need to know if it succeeds or not.What is the best way to do that? I can't seem to find examples of kicking off what you might call an "orphan" background task in ASP.NET.
I thought of doing it via a javascript Ajax call on the page I show to the user, but the information passed to the web service is sensitive, so that's out of the question. But that kind of illustrates what I want to do.
[ed] Another idea: Is there an event in the ASP.NET model I can use which occurs after the response has been sent to the browser and the connection closed? ie. So more processing can occur without the user waiting for it?
View 2 Replies
Mar 2, 2011
I have a function in a module that returns a datatable.I need to call that function asynchronously and get the results in the Main thread (Main Form) in vb.net.
View 2 Replies