Windows Application using Thread

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sekarm
    New Member
    • Mar 2007
    • 26

    Windows Application using Thread

    Dear guys,
    In C# windows application i am using four threads for seperate process. Each thread done seperate job.i want to monitor the thread process in main windows form.so each thread update data in windows controls in mainForm.By using this i got the exception "Cross thread operation not valid", so i am using Invoke method for access controls in mainform.by using this i am write if loop for invoke the control using delegate.Is any other way for accessing controls using thread.

    Thanks & Regards,
    Sekar M
  • mwalts
    New Member
    • May 2007
    • 38

    #2
    Originally posted by sekarm
    Dear guys,
    In C# windows application i am using four threads for seperate process. Each thread done seperate job.i want to monitor the thread process in main windows form.so each thread update data in windows controls in mainForm.By using this i got the exception "Cross thread operation not valid", so i am using Invoke method for access controls in mainform.by using this i am write if loop for invoke the control using delegate.Is any other way for accessing controls using thread.

    Thanks & Regards,
    Sekar M
    You have to use invoke to change values on the main thread. Which means you need to use delegates. You can pass parameters with delegates, look at this article and it should sort you out.

    http://www.yoda.arachs ys.com/csharp/threads/winforms.shtml

    Have fun,

    -mwalts

    Comment

    • sekarm
      New Member
      • Mar 2007
      • 26

      #3
      Dear mwalts,
      I already have that idea man, i want to access controls through threads except using invoke and delegates.

      Thanks & Regards,
      Sekar M

      Comment

      • sekarm
        New Member
        • Mar 2007
        • 26

        #4
        Dear Guyz,
        I saw the important concept in windows application. If Thread access the Controls in Windows Form the Exception will throw "Cross-thread operation not valid: Control 'label1' accessed from a thread other than the thread
        it was created on.".
        To rectify this error all developers use InvokeRequired and Invoke Property. Apart from this using the following code in C#.Net.
        Code:
         Form1.CheckForIllegalCrossThreadCalls = false;
        Code:
        Control.CheckForIllegalCrossThreadCalls = false;
        if use this code you may not use InvokeRequired and Invoke Property. Please let me know if you have any concerns.

        Best Wishes,
        ....Sekar

        Comment

        Working...