Before reading the following knowledge, I already think you already have C # Foundation, including simple delegate knowledge; Code is developed using VS2008, but will be written in the. Net Framework 2.0 (C Sharp)
What is. NET asynchronous mechanism?
Before we explain this topic, let's look at the synchronized program, which is our usual Hello World program.
Code 1:
1 class Program
2 {
3 static void Main (string[] args)
4 {
5//view current thread ID, whether threads in thread pool
6 Console.WriteLine ("1,thread Id:#{0},is poolthread?{ 1} ",
Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread);
7
8 Asynctest test = new Asynctest ();
9 String val = Test. Hello ("Andy Huang");
Console.WriteLine (val);
Console.ReadLine (); Let the black screen wait, not directly off.
The public
class Asynctest {# public
string Hello (string name)
19 {
20//view current thread ID, whether threads in thread pool
Console.WriteLine ("2,thread Id:#{0},is poolthread?{ 1} ",
Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread);
Return "Hello:" + name;
24}
Figure 1