Free mag vol1 | Page 804

CHAPTER 19  MULTITHREADED, PARALLEL, AND ASYNC PROGRAMMING await Task.Run(() => { Thread.Sleep(2000); }); MessageBox.Show("Done with second task!"); await Task.Run(() => { Thread.Sleep(2000); }); MessageBox.Show("Done with third task!"); } Again, here each task is not doing much more than suspending the current thread for a spell; however, any unit of work could be represented by these tasks (calling a web service, reading a database, or what have you). In any case, let’s summarize the key points of this example, as follows: • Methods (as well as lambda expressions or anonymous methods) can be marked with the async keyword to enable the method to do