Ejemplo n.º 1
0
        // 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();
        }
Ejemplo n.º 2
0
        private static void Main()
        {
            IStockQuote qt = new StockQuote();
            WebService svc = new WebService(qt);

            FetchStockQuotesSync(svc);
            FetchStockQuotesApm(svc);
#if AsyncEnumerator
            FetchStockQuotesAsyncEnumerator(svc);
#endif
            FetchStockQuotesAsyncCtp(svc);

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        // Async CTP

        private static async void FetchStockQuotesAsyncCtp(WebService svc)
        {
            IStockQuote qt = await svc.FetchStockQuotesTaskAsync();
        }
Ejemplo n.º 4
0
 private static IEnumerator<Int32> FetchStockQuotesAsyncEnumerator(AsyncEnumerator ae, WebService svc)
 {
     svc.BeginFetchStockQuotes(ae.End(), null);
     yield return 1;
     IStockQuote qt = svc.EndFetchStockQuotes(ae.DequeueAsyncResult());
 }
Ejemplo n.º 5
0
        // AsyncEnumerator class.

        private static void FetchStockQuotesAsyncEnumerator(WebService svc)
        {
            AsyncEnumerator ae = new AsyncEnumerator();
            ae.BeginExecute(FetchStockQuotesAsyncEnumerator(ae, svc), ae.EndExecute);
        }
Ejemplo n.º 6
0
 private static void FetchStockQuotesApm(WebService svc)
 {
     Func<IStockQuote> @delegate = svc.FetchStockQuotes; 
     // This never blocks. Your code returns immediately.
     @delegate.BeginInvoke(FetchStockQuotesApmCallback, @delegate);
 }
Ejemplo n.º 7
0
        // IAsyncResult interface (APM).
#if AsyncEnumerator
        private static void FetchStockQuotesApm(WebService svc)
        {
            // This never blocks. Your code returns immediately.
            svc.BeginFetchStockQuotes(FetchStockQuotesApmCallback, svc);
        }