This sample shows you how to do threading.
class ThreadPriority { public static void Main() { Thread thread = Thread.CurrentThread; Console.WriteLine ("Priority: {0}", thread.Priority); } }
class ThreadPoolThread { public static void Main() { Thread thread = Thread.CurrentThread; Console.WriteLine ("IsThreadPoolThread: {0}", thread.IsThreadPoolThread); } } class ThreadAlive { public static void Main() { Thread thread = Thread.CurrentThread; Console.WriteLine ("IsAlive: {0}", thread.IsAlive); } }
class ThreadBackground { public static void Main() { Thread thread = Thread.CurrentThread; Console.WriteLine ("IsBackground: {0}", thread.IsBackground); } } class ThreadState { public static void Main() { Thread thread = Thread.CurrentThread; Console.WriteLine ("ThreadState: {0}", thread.ThreadState); } } class ThreadName { public static void Main() { Thread thread = Thread.CurrentThread; Console.WriteLine ("Name: {0}", thread.Name); } } class ThreadName { public static void Main() { Thread thread = Thread.CurrentThread; thread.Name = ".NET Thread"; } }
class TimerCallBack { public static AutoResetEvent autoResetEvent = new AutoResetEvent (false); public static Timer timer = null; public const int iterations = 4; public class State { public int count = 0; } static void CallBack (Object stateObject) { State state = (State) stateObject; Console.WriteLine ("{0} count = {1}", DateTime.Now, state.count++); if (state.count > iterations) { timer.Dispose (autoResetEvent); } } public static void Main() { timer = new Timer (new TimerCallback (CallBack), new State(), 1000, 2000); autoResetEvent.WaitOne(); } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|