This recipe will describe how to put an asynchronous operation on a thread pool.
To step into this recipe, you will need Visual Studio 2012. There are no other prerequisites. The source code for this recipe could be found in BookSamples\Chapter3\Recipe2
.
To understand how to post an asynchronous operation on a thread pool, perform the following steps:
Start Visual Studio 2012. Create a new C# Console Application project.
In the
Program.cs
file, add the followingusing
directives:using System; usingSystem.Threading;
Add the following code snippet below the
Main
method:private static void AsyncOperation(object state) { Console.WriteLine("Operation state: {0}",state ?? "(null)"); Console.WriteLine("Worker thread id: {0}",Thread.CurrentThread.ManagedThreadId); Thread.Sleep(TimeSpan.FromSeconds(2)); }
Add the following code snippet inside the
Main
method:const int x = 1; const int y = 2; const string lambdaState =...