This is a mirror of official site: http://jasper-net.blogspot.com/

A C# Threading Reference Manual

| Sunday, May 9, 2010
A thread is a unit of execution. Microsoft has used threads since the Win32 and NT days, and an understanding of it necessary. In my limited knowledge, I have assembled a “manual” that could act as a reference for things like basic threading and using threading in the real world. This section, while part of the article, is only meant to be a basic introduction to the concept of threading. The one experienced in threading should overlook it. To create a thread, you must follow these steps:

Create a method that takes no arguments and does not return any data
Create a new ThreadStart delegate and specify the method created in step 1.
Create a Thread object, specifying the ThreadStart object created in step 2.
Call ThreadStart to begin execution of the new thread. The code will look something like this:


using System;
using System.Threading;
public class Program 

{
public static void Main() 
{
ThreadStart operation = new ThreadStart(SimpleWork);
Thread thr = new Thread(operation);
thr.Start();
}

private static void SimpleWork()
{
Console.WriteLine("Thread:  {0}", Thread.CurrentThread.ManagedThreadId);
}
}

Here are some of the Thread class’s Properties:

IsAlive: Gets a value indicating that the current thread is currently executing
IsBackground: Gets or sets whether the thread runs as a background thread.
IsThreadPoolId: Gets whether this thread is a thread in the thread pool.
ManagedThreadId: Gets a number to identify the current thread.
Name: Gets or sets a name associated with the thread.
Priority: Gets or sets the priority of the thread.
ThreadState: Gets the ThreadState value for the thread.

Read more: Codeproject

Posted via email from jasper22's posterous

0 comments: