Threading Problem
jbsound
Posts: 35
There seems to be a problem with threading using the Status functionality of the Database class. There is no problem using the Executor, for example.
I'm using the following code for the Executor:
StatusCallback updates a progress bar and a list component.
If I want to use the same functionality with the Database class, then Visual Studio pops an error stating that the cross-thread operation is not valid when I attempt to update the progress bar or the list component.
Here is my code for the Database:
Any suggestions how to work around this issue?
Thanks,
JB
I'm using the following code for the Executor:
Dim executor As BlockExecutor = New BlockExecutor executor.Status = New StatusEventHandler(AddressOf StatusCallback)
StatusCallback updates a progress bar and a list component.
If I want to use the same functionality with the Database class, then Visual Studio pops an error stating that the cross-thread operation is not valid when I attempt to update the progress bar or the list component.
Here is my code for the Database:
Dim db1 As New Database() db1.Status = New StatusEventHandler(AddressOf StatusCallback)
Any suggestions how to work around this issue?
Thanks,
JB
Comments
The execution happens on a different thread, so the error is correct. Check out the Packager Template C# for some ideas on how to implement your progress dialog box. This template code has similar problems to overcome.
(The template code does not display the dialog box if the task is very quick, you could strip out this code to make it easier to understand. )
The template code has an event handler that takes event and then invokes using this code In order to the information back on to the main UI thread.
Hope this helps.
David