How access page controls (label, timer, etc) inside a thread (ASP.NET Web Forms)

972 views Asked by At

here is my thread in asp.net web page (code behind) :

Thread my_thread = new Thread(delegate()
{
    my_thread_method(params);
});

Timer1.Enabled = true;

my_thread.Start();

Now I want to access Timer1 in my_thread() and work with that timer.
How can i do that?
I also need to update some labels text inside thread, but I don't have access to them.
What is the solution?

2

There are 2 answers

6
Justin Harvey On BEST ANSWER

my_thread_method needs to be defined in the same class as the controls in order for you to access them.

You will then need to read this sort of thing to call UI classes correctly from the non-UI thread:

How to update the GUI from another thread in C#?

EDIT
this answer is not related to asp.net web forms.
so we can not accept this.

2
Crumbleszatan On

For update controls in Thread, you have to use invoke method.

Go to : C# Threading using invoke, freezing the form