Threading in Windows Forms

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

    #1

    Threading in Windows Forms

    Dear All,
    Happy to see you all again. I got some useful information from this forum. thats why i am asking. Please give me the valuable information.

    I have to run 4 threads parallely in windows form. These Threads to be run on some intervals, so i put in While Loop that is,

    Code:
    While(IsAvailable) 
    {
    Thread.Start();
    Thread.Sleep(Timespan.FromSeconds(4));
    }
    The Variable Isavailable set as = true;

    All thread are run in same way. If I want to Exit the application i just reset the variable in While Loop IsAvailable = false. and then abort the threads. In above 4 threads 2 thread functions are complicated so thats 2 threads are in running stage the application does not to be closed. After completion of 2 threads the application will be closed. so what i have to do?
    And one more question is any other way to wait the thread. if i have put sleep mode its wastes the cpu time. Give your valuable Solution..

    Thanks in Advance,
    Sekar.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by sekarm
    Dear All,
    Happy to see you all again. I got some useful information from this forum. thats why i am asking. Please give me the valuable information.

    I have to run 4 threads parallely in windows form. These Threads to be run on some intervals, so i put in While Loop that is,

    Code:
    While(IsAvailable) 
    {
    Thread.Start();
    Thread.Sleep(Timespan.FromSeconds(4));
    }
    The Variable Isavailable set as = true;

    All thread are run in same way. If I want to Exit the application i just reset the variable in While Loop IsAvailable = false. and then abort the threads. In above 4 threads 2 thread functions are complicated so thats 2 threads are in running stage the application does not to be closed. After completion of 2 threads the application will be closed. so what i have to do?
    And one more question is any other way to wait the thread. if i have put sleep mode its wastes the cpu time. Give your valuable Solution..

    Thanks in Advance,
    Sekar.
    Hi Sekar,

    I haven't use threads since school...but I did a bit of research on the problem for you and did find some useful things on MSDN that may help you out.

    According to the Thread Members listed (in the last link) it doesn't look like there is a wait function that does what you'd like it to do. There is a SpinWait function that lets you set the number of iterations the thread should wait for though...

    Be sure to check out the information on thread pools. I think this will help you out as well.

    Cheers!
    -Frinny

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      If you want your "threads" to only run at a given interval, take a look at the Timer object.

      There are a few:
      System.Threadin g.Timer
      System.Windows. Forms.Timer
      System.Timers.T imer

      MSDN has pretty good help on them.

      Comment

      • OwfAdmin
        New Member
        • Jul 2007
        • 2

        #4
        Use this safe abortable thread class publish on MSDN
        http://msdn.microsoft.com/msdnmag/is...03/NETMatters/

        <email removed>

        Originally posted by sekarm
        Dear All,
        Happy to see you all again. I got some useful information from this forum. thats why i am asking. Please give me the valuable information.

        I have to run 4 threads parallely in windows form. These Threads to be run on some intervals, so i put in While Loop that is,

        Code:
        While(IsAvailable) 
        {
        Thread.Start();
        Thread.Sleep(Timespan.FromSeconds(4));
        }
        The Variable Isavailable set as = true;

        All thread are run in same way. If I want to Exit the application i just reset the variable in While Loop IsAvailable = false. and then abort the threads. In above 4 threads 2 thread functions are complicated so thats 2 threads are in running stage the application does not to be closed. After completion of 2 threads the application will be closed. so what i have to do?
        And one more question is any other way to wait the thread. if i have put sleep mode its wastes the cpu time. Give your valuable Solution..

        Thanks in Advance,
        Sekar.
        Last edited by Frinavale; Jul 10 '07, 01:04 PM. Reason: Removed email link

        Comment

        Working...