Thread Issues c# 2.0
-
Hi, Using csharp and the .net farmework i could run a thread like this and update the UI such as a label. example : Thread mythread = new Thread(new Threadstart(myfunction)); mythread.Start(); void myfunction() { lblstatus.text = DoWork(); } Now using this same code which works in vS 1.1 dont wanna update the UI label in net 2.0 Why ?? :( Im using c# expression edition . Thanks in advance
-
Hi, Using csharp and the .net farmework i could run a thread like this and update the UI such as a label. example : Thread mythread = new Thread(new Threadstart(myfunction)); mythread.Start(); void myfunction() { lblstatus.text = DoWork(); } Now using this same code which works in vS 1.1 dont wanna update the UI label in net 2.0 Why ?? :( Im using c# expression edition . Thanks in advance
Trance Junkie wrote:
Now using this same code which works in vS 1.1 dont wanna update the UI label in net 2.0
What do u mean? throws an exception, hangs? From what i know, you should never use a non UI thread to update the UI, it causes it to deadlock.
-
Hi, Using csharp and the .net farmework i could run a thread like this and update the UI such as a label. example : Thread mythread = new Thread(new Threadstart(myfunction)); mythread.Start(); void myfunction() { lblstatus.text = DoWork(); } Now using this same code which works in vS 1.1 dont wanna update the UI label in net 2.0 Why ?? :( Im using c# expression edition . Thanks in advance
It's not safe to access UI controls from threads other than the one they were created on. It mostly results in a freezing UI or other strange things. You're lucky nothing of this happened in your case. As there are many other people like you who weren't aware of this problem and accessed UI controls from other threads, it's no longer allowed. Use Invoke or BeginInvoke to update your label. This article[^] should help you.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
Trance Junkie wrote:
Now using this same code which works in vS 1.1 dont wanna update the UI label in net 2.0
What do u mean? throws an exception, hangs? From what i know, you should never use a non UI thread to update the UI, it causes it to deadlock.
Hi thanks for the speedy reply :-) No, it does not even get an exception, nothing of that sort and it does not even hang. emmm this is very strange.... :confused:
-
It's not safe to access UI controls from threads other than the one they were created on. It mostly results in a freezing UI or other strange things. You're lucky nothing of this happened in your case. As there are many other people like you who weren't aware of this problem and accessed UI controls from other threads, it's no longer allowed. Use Invoke or BeginInvoke to update your label. This article[^] should help you.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
Thank you Stefan i`ll check out the article. :rose: