views:

121

answers:

1

Hi,

I have thread that monitor the status of the device( using i/o ). This will fire the event to several UI (Forms/Dialogs..) parts about the connection status(Connected, Disconnected, Fault). Based on this status, the forms and dialogs are destroyed, created , enabled and disabled.

My Problem :

   I getting Cross-Thread exception because the thread doing the operations like Dispose the from, create the from .... .  I using smart client, forms and dialogs are part of the WorkItemController and i just terminating that.

I don't want u use Invoke or BeginInvoke . I want this thread to continue only monitoring the status. SO that this thread has to give its control to the main thread and the main thread will close the form or create the form.

Just i want how to shift the control from one thread to another. Is any way is there?

+1  A: 

The best solution is to use Invoke to switch back to your mainthread.

or if you can use global variables shared between the main thread and your background thread, but this means your main thread should check the variables in a loop and this may hang GUI.

Or use System.Windows.Forms.Timer as it executes in the main thread.

Ahmed Said