CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2003
    Posts
    17

    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.

  2. #2
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    have you tried using Timer class.
    I think you should try for that.

    Paresh
    - Software Architect

  3. #3
    Join Date
    Mar 2003
    Posts
    17
    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.

  4. #4
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    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

  5. #5
    Join Date
    Jul 2002
    Location
    EU
    Posts
    68

    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

  6. #6
    Join Date
    Mar 2003
    Posts
    17

    Re: Threading and GUI

    Originally posted by petru66
    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
    Thanks, this is just what I'm looking for.

  7. #7
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    nice article though !
    actually when you create a multithreading on your own then only you will realize pits-and-pots of it.
    - Software Architect

  8. #8
    Join Date
    Mar 2003
    Posts
    17
    Exactly! Once I tried to do in VB6 and resulted in a total mess.

  9. #9
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    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
  •  





Click Here to Expand Forum to Full Width

Featured