O'Reilly logo

C# Multithreaded and Parallel Programming by Rodney Ringler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using an AsyncCallback delegate method

We have seen how we can use the APM design pattern that is implemented in the FileStream class to perform an asynchronous read and then wait on the results. We also mentioned how we can poll to see if the asynchronous read has completed instead of blocking the main thread. Now, we will see how we can execute a delegate method when the asynchronous read has completed.

Using this method, we do not have to block the main thread waiting or perform the work of polling the IsCompleted property to see when the read has completed. We simply execute the BeginRead method and pass it a delegate method. We then go on our way and, when the read completes, the delegate method will be executed.

Let's look at the method header ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required