Beispiel #1
0
        private static Task <int> AccessTheWebAsync()
        {
            Program.AccessTheWebAsyncd__2 stateMachine = new Program.AccessTheWebAsyncd__2();
            stateMachine.t__builder = AsyncTaskMethodBuilder <int> .Create();

            stateMachine.__state = -1;
            stateMachine.t__builder.Start <Program.AccessTheWebAsyncd__2>(ref stateMachine);
            return(stateMachine.t__builder.Task);
        }
Beispiel #2
0
            void IAsyncStateMachine.MoveNext()
            {
                int num1 = this.__state;
                int length;

                try
                {
                    TaskAwaiter <string> awaiter;
                    if (num1 != 0)
                    {
                        Console.WriteLine("\r\nTWO:   Entering AccessTheWebAsync.");
                        HttpClient httpClient = new HttpClient();
                        long       num3       = 1000000;
                        httpClient.MaxResponseContentBufferSize = num3;
                        this.client5__1 = httpClient;
                        Console.WriteLine("\r\n           Calling HttpClient.GetStringAsync.\r\n");
                        this.getStringTask5__2 = this.client5__1.GetStringAsync("http://msdn.microsoft.com");
                        Console.WriteLine("\r\nTHREE: Back in AccessTheWebAsync.\r\n           Task getStringTask is started.");
                        Console.WriteLine("\r\n           About to await getStringTask and return a Task<int> to startButton_Click.\r\n");
                        awaiter = this.getStringTask5__2.GetAwaiter();
                        if (!awaiter.IsCompleted)
                        {
                            this.__state = 0;
                            this.u__1    = awaiter;
                            Program.AccessTheWebAsyncd__2 stateMachine = this;
                            this.t__builder.AwaitUnsafeOnCompleted <TaskAwaiter <string>, Program.AccessTheWebAsyncd__2>(ref awaiter, ref stateMachine);
                            return;
                        }
                    }
                    else
                    {
                        awaiter      = this.u__1;
                        this.u__1    = new TaskAwaiter <string>();
                        this.__state = -1;
                    }
                    string result = awaiter.GetResult();
                    new TaskAwaiter <string>();
                    this.s__4            = result;
                    this.urlContents5__3 = this.s__4;
                    this.s__4            = (string)null;
                    Console.WriteLine("\r\nFIVE:  Back in AccessTheWebAsync.\r\n           Task getStringTask is complete.\r\n           Processing the return statement.\r\n           Exiting from AccessTheWebAsync.\r\n");
                    length = this.urlContents5__3.Length;
                }
                catch (Exception ex)
                {
                    this.__state = -2;
                    this.t__builder.SetException(ex);
                    return;
                }
                this.__state = -2;
                this.t__builder.SetResult(length);
            }