Demonstates starting and waiting on a thread : Thread Start Wait « Thread « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Thread » Thread Start WaitScreenshots 
Demonstates starting and waiting on a thread
Demonstates starting and waiting on a thread

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

// Thread.cs -- Demonstates starting and waiting on a thread
//
//              Compile this program with the following command line:
//                  C:>csc Thread.cs
using System;
using System.Windows.Forms;
using System.Threading;

namespace nsThreads
{
    public class ThreadDemo
    {
        static public void Main ()
        {
// Create the new thread object
            Thread NewThread = new Thread (new ThreadStart (RunThread));
// Show a message box.
            MessageBox.Show ("Click OK to start the thread""Thread Start");
// Start the new thread.
            NewThread.Start ();
// Inform everybody that the main thread is waiting
            Console.WriteLine ("Waiting . . .");
// Wait for NewThread to terminate.
            NewThread.Join ();
// And it's done.
            Console.WriteLine ("\r\nDone . . .");
        }

// Method to assign to the new thread as its start method
        static public void RunThread ()
        {
// Sleep for a second, print and message and repeat.
            for (int x = 5; x > 0; --x)
            {
                Thread.Sleep (1000);
                Console.Write ("Thread is running. {0} second{1}  \r",
                               x, x > "s" "");
            }
// The thread will terminate at this point. It will not return to
// the method that started it.
        }
    }
}


           
       
Related examples in the same category
1.Threads:Waiting with WaitHandleThreads:Waiting with WaitHandle
2.Thread SampleThread Sample
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.