Click or drag to resize

How To Use AsyncInit on Silverlight

This topic details the steps necessary for creating asynchronously initialized types with AsyncInit on Silverlight 4 and 5.

Silverlight 4 and 5 won't allow anyone other than the declaring type access to private members, requiring a slightly different procedure.

  1. Declare an internal (rather than private) constructor:

    C#
    internal UniversalAnswerService()
    : base(null)
    {
    }
  2. Expose it to Ditto.AsyncInit by adding the following attribute to Properties\AssemblyInfo.cs:

    C#
    [assembly: InternalsVisibleTo("Ditto.AsyncInit")]
Your class may now be consumed asynchronously:
Example
C#
var service = await UniversalAnswerService.CreateAsync(progress, cancellationToken);
var answer = service.Answer;
Since all asynchronously initialized types must declare internal constructors (on Silverlight), it is advisable to keep them in an assembly of their own, in order to prevent others from inadvertently accessing uninitialized instances thereof.
See Also