private static IEnumerator <Int32> FetchStockQuotesAsyncEnumerator(AsyncEnumerator ae, WebService svc) { svc.BeginFetchStockQuotes(ae.End(), null); yield return(1); IStockQuote qt = svc.EndFetchStockQuotes(ae.DequeueAsyncResult()); }
// Sync. private static void FetchStockQuotesSync(WebService svc) { // This blocks. You don't know when the FetchStockQuotes // method returns. It may takes from minutes, to hours or // it may not return at all. IStockQuote qt = svc.FetchStockQuotes(); }
private void GetStockQuotesHelper(Object state) { // We know that it's really an AsyncResult<IStockQuote> object. AsyncResult <IStockQuote> ar = (AsyncResult <IStockQuote>)state; try { // Perform the operation; if sucessful set the result. IStockQuote quotes = FetchStockQuotes(); ar.SetAsCompleted(quotes, false); } catch (Exception e) { // If operation fails, set the exception. ar.SetAsCompleted(e, false); } }
/// <summary> /// Initializes a new instance of the <see cref="WebService"/> class. /// </summary> /// <param name="quotes">The quotes.</param> public WebService(IStockQuote quotes) { m_quotes = quotes; }
public WebApp(IAuthenticator authenticator, IStockQuote quotes) { this.authenticator = authenticator; this.quotes = quotes; }
public WebApp(IAuthenticator authenticator, IStockQuote stockQuote) { _authenticator = authenticator; _stockQuote = stockQuote; }
public WebService(IAuthenticator authenticator, IStockQuote quotes) { _authenticator = authenticator; _quotes = quotes; }
public WebService(IAuthenticator authenticator, IStockQuote quotes) { this.authenticator = authenticator; this.quotes = quotes; }
public WebApp(IAuthenticator authenticator, IStockQuote stockQuote) { this.Authenticator = authenticator; this.StockQuote = stockQuote; }
// Async CTP private static async void FetchStockQuotesAsyncCtp(WebService svc) { IStockQuote qt = await svc.FetchStockQuotesTaskAsync(); }
private static void FetchStockQuotesApmCallback(IAsyncResult ar) { // This never blocks. Your code returns immediately. Func <IStockQuote> @delegate = (Func <IStockQuote>)ar.AsyncState; IStockQuote qt = @delegate.EndInvoke(ar); }
private static void FetchStockQuotesApmCallback(IAsyncResult ar) { // This never blocks. Your code returns immediately. WebService svc = (WebService)ar.AsyncState; IStockQuote qt = svc.EndFetchStockQuotes(ar); }