How to access the controls created in Main thread from a worker thread?

Hi All,

I am developing an application for PocketPC in C#.NET, VS2005. It contains a form and few buttons.


When the application starts, an worker thread will be created. At certain point of time during the course of execution, the worker thread will be trminated. Before terminating the thread, I have to set the 'visible' property of a button to 'false'..
When I try to do that inside the worker thread, it is raising the following Exception

Control.Invoke must be used to interact with controls created on a separate thread.

How can I be able to access the property of the button created in main thread from the worker thread...



Answer this question

How to access the controls created in Main thread from a worker thread?

  • Rykin Poe

    Hi Khan,

    I am not clear about your point...

    Can you please elaborate it


  • Jack Wheeler

    You should use Control.Invoke(), please see MSDN for samples.



  • bilalso

    Hi

    You can call the some operation from one thread in another thread through Asynchronus machinisim.



  • Leslie Mason

    Thanks Ilya..

    Control.Invoke() rectified my problem...


  • How to access the controls created in Main thread from a worker thread?