C# Class ContinuationExample.MainForm

Inheritance: System.Windows.Forms.Form
Afficher le fichier Open project: drmohundro/presentations

Méthodes publiques

Méthode Description
MainForm ( ) : System

Méthodes protégées

Méthode Description
Dispose ( bool disposing ) : void

Clean up any resources being used.

Private Methods

Méthode Description
CalculateRandomNumber ( ) : int

Our really complicated, long running method

DoWorkWithAsync ( ) : Task

Example of using async/await to add threading (non-blocking) to our app. Can you see how these are basically doing the same thing?

DoWorkWithManualContinuations ( ) : IEnumerable

Example of using continuations (with coroutines) to add threading (non-blocking) to our app. Still using yield return, but our caller doesn't just enumerate the results because we don't want to block the UI. However, we're not having to use callbacks here. Why not? See AsyncResult code + the calling code. This ideas was popularized in .NET by the Caliburn library (which Deployer uses).

ExecuteContinuation ( IEnumerator enumerator ) : void

Recursively call continuations... it doesn't care about threads or not

GetRandomNumbers ( int numberOfRandomsToReturn ) : IEnumerable

Example of yield return here... C#'s implementation of coroutines Just syntactic sugar for returning an enumerable... except that it "yields" control to the calling method before going to the next option. And it is up to the caller to ask for the next result. (note the order of writelines) This is lazy evaluation works with LINQ (IQueryable)

GetRandomNumbersAsync ( int numberOfRandomsToReturn ) : Task

Example of using async/await to add threading (non-blocking) to our app. Can you see how these are basically doing the same thing?

GetRandomNumbersContinuation ( int numberOfRandomsToReturn ) : IEnumerable

Example of using continuations (with coroutines) to add threading (non-blocking) to our app. Still using yield return, but our caller doesn't just enumerate the results because we don't want to block the UI. However, we're not having to use callbacks here. Why not? See AsyncResult code + the calling code. This ideas was popularized in .NET by the Caliburn library (which Deployer uses).

InitializeComponent ( ) : void

Required method for Designer support - do not modify the contents of this method with the code editor.

btnDoWorkAsync_Click ( object sender, EventArgs e ) : void

C# does this for us natively now. Awesome.

btnDoWorkContinuation_Click ( object sender, EventArgs e ) : void

This call will NOT block the UI thread.

btnDoWorkNormal_Click ( object sender, EventArgs e ) : void

This call will block the UI thread... it also shows off the C# yield statement

btnNonBlockedUIManual_Click ( object sender, EventArgs e ) : void

Method Details

Dispose() protected méthode

Clean up any resources being used.
protected Dispose ( bool disposing ) : void
disposing bool true if managed resources should be disposed; otherwise, false.
Résultat void

MainForm() public méthode

public MainForm ( ) : System
Résultat System