Asynchronous programming was first released for Microsoft Visual Studio 2012 as an add-on, and is now natively available in Microsoft Visual Studio 2013. Asynchronous programming is also available with a special pattern called async
/await
, which is greatly optimized for cross-thread operations.
This pattern helps to achieve asynchronous programming in a simplified way and adds a transparent (to programmers) asynchronous/synchronous jump, row-by-row, with the ability to execute code on the UI, creating threads without having to use any dispatcher or a delegate. The following is an example from the legacy Windows Forms as seen earlier:
public Form1() { InitializeComponent(); OnAsyncWay(); } private async Task OnAsyncWay() { //running in creating thread //async elaboration //this starts a new task that returns the required value var text = await Task.Factory.StartNew(() => { //running on another thread Thread.Sleep(1000); return...