Ejemplo n.º 1
0
        private static Task <long?> GetPageLengthAsync()
        {
            Program.AsyncStateMachine stateMachine = new Program.AsyncStateMachine();
            stateMachine.Builder = AsyncTaskMethodBuilder <long?> .Create();

            stateMachine.State = -1;
            stateMachine.Builder.Start <Program.AsyncStateMachine>(ref stateMachine);
            return(stateMachine.Builder.Task);
        }
Ejemplo n.º 2
0
            void IAsyncStateMachine.MoveNext()
            {
                int  num1 = this.State;
                long?contentLength;

                try
                {
                    TaskAwaiter <HttpResponseMessage> awaiter;
                    int num2;
                    if (num1 != 0)
                    {
                        this._client = new HttpClient();
                        awaiter      = this._client.GetAsync("http://apress.com").GetAwaiter();
                        if (!awaiter.IsCompleted)
                        {
                            this.State    = num2 = 0;
                            this._awaiter = awaiter;
                            Program.AsyncStateMachine stateMachine = this;
                            this.Builder.AwaitUnsafeOnCompleted <TaskAwaiter <HttpResponseMessage>, Program.AsyncStateMachine> (ref awaiter, ref stateMachine);
                            return;
                        }
                    }
                    else
                    {
                        awaiter       = this._awaiter;
                        this._awaiter = new TaskAwaiter <HttpResponseMessage>();
                        this.State    = num2 = -1;
                    }
                    this._responce2 = awaiter.GetResult();
                    this._responce1 = this._responce2;
                    this._responce2 = (HttpResponseMessage)null;
                    contentLength   = this._responce1.Content.Headers.ContentLength;
                }
                catch (Exception ex)
                {
                    this.State = -2;
                    this.Builder.SetException(ex);
                    return;
                }
                this.State = -2;
                this.Builder.SetResult(contentLength);
            }