Home
Browse all 647 examples
Download all 647 examples
Download sample chapters
Reviews
Errata
Acknowledgments
Links on .NET
Paradoxal Press
Buy directly from Paradoxal Press at $33.99 (Save 43%)
Category: Programming
Level: Beginner to seasoned
900 pages
ISBN-10 097661322-0
ISBN-13 978-097661322-0
$59.99 USA
$79.99 CANADA
|
Listing 5-3 extracted from chapter
Processes, threads and synchronization
Listing 5-2< > Listing 5-4
This listing can be compiled with the command line: csc.exe /target:exe Example_5_3.cs Errors: 0 Warnings: 0
Example_5_3.cs
using System.Threading;
class Program {
static void f1() { System.Console.WriteLine("f1"); }
void f2() { System.Console.WriteLine("f2"); }
static void f3( object obj ) { System.Console.WriteLine(
"f3 obj = {0}",obj); }
static void Main() {
// Explicitly specify the delegate class 'ThreadStart'.
Thread t1 = new Thread( new ThreadStart(f1) );
Program program = new Program();
// Here, we use the C#2 facility to infer the delegate class
// 'ThreadStart' from the definition of the 'Thread' class
// constructor without argument.
Thread t2 = new Thread( program.f2 );
// Here, the C#2 compiler infer the delegate class
// 'ParametrizedThreadStart' since the 'f3()' method
// accept an 'object' parameter.
Thread t3 = new Thread( f3 );
t1.Start(); t2.Start(); t3.Start("hello");
t1.Join(); t2.Join(); t3.Join();
}
}
Copyright Patrick Smacchia 2006 2007
|