|
-
March 18th, 2003, 05:42 PM
#1
GUI Threading in C#
I'm not sure whether I can describe this problem clearly, here is my best shot.
I had a class say ClassA and a method MethodA. In MethodA, it will spawn several threads to do their work. Within these spawned threads, some progress information will be reported. Now the problem is that my classes works fine in command line env (e.g. if I just print out some message to stdout from spawned threads for reporting progresses) but failed in a GUI env (e.g. reporting by adding text to a text component). Seems the problem is that my code called a gui function (like TextBox.text="xxx") in some other threads than the from the default gui thread.
I remembered reading some material on this, like the gui event handlers runs in a thread and you can't just call a gui method from other threads. You need some special treatment. But I can't remember the source. Could anyone help me?
Thank.
-
March 18th, 2003, 05:45 PM
#2
have you tried using Timer class.
I think you should try for that.
Paresh
- Software Architect
-
March 18th, 2003, 05:49 PM
#3
You mean using a timer to periodically check status info for sub-threads? That would avoid calling back a gui function from non-gui threads.
I'll try that I think.
-
March 18th, 2003, 06:22 PM
#4
Timer is a UI control when u drag and drop it in ur form and just implement the method ...
and start timer in load method of the form.
so u can there update UI.
there are some conflicts btw threads and UI updates so u need to carefully design it..
Paresh
- Software Architect
-
March 19th, 2003, 08:33 AM
#5
Threading and GUI
I think the following article gives the answer to the initial question:
http://msdn.microsoft.com/library/de...ms06112002.asp
Its sequels are also worth reading - a little bit more advanced, though.
It helped me a lot.
Petru
-
March 19th, 2003, 11:46 AM
#6
Re: Threading and GUI
Thanks, this is just what I'm looking for.
-
March 19th, 2003, 02:48 PM
#7
nice article though !
actually when you create a multithreading on your own then only you will realize pits-and-pots of it.
- Software Architect
-
March 19th, 2003, 04:13 PM
#8
Exactly! Once I tried to do in VB6 and resulted in a total mess.
-
March 20th, 2003, 08:43 PM
#9
what type of mess thou.
- Software Architect
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|