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.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.