Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| //<Snippet4> | |
| using System; | |
| using System.Threading; | |
| namespace Examples.AdvancedProgramming.AsynchronousOperations | |
| { | |
| public class AsyncMain | |
| { | |
| static void Main() { | |
| // The asynchronous method puts the thread id here. | |
| int threadId; | |
| // Create an instance of the test class. | |
| AsyncDemo ad = new AsyncDemo(); | |
| // Create the delegate. | |
| AsyncMethodCaller caller = new AsyncMethodCaller(ad.TestMethod); | |
| // Initiate the asychronous call. | |
| IAsyncResult result = caller.BeginInvoke(3000, | |
| out threadId, null, null); | |
| // Poll while simulating work. | |
| while(result.IsCompleted == false) { | |
| Thread.Sleep(250); | |
| Console.Write("."); | |
| } | |
| // Call EndInvoke to retrieve the results. | |
| string returnValue = caller.EndInvoke(out threadId, result); | |
| Console.WriteLine("\nThe call executed on thread {0}, with return value \"{1}\".", | |
| threadId, returnValue); | |
| } | |
| } | |
| } | |
| /* This example produces output similar to the following: | |
| Test method begins. | |
| ............. | |
| The call executed on thread 3, with return value "My call time was 3000.". | |
| */ | |
| //</Snippet4> | |