DisplayPageSizeAsync(string url, int line)
        {
            WebRequest      webRequest = WebRequest.Create(url);
            WebRequestState state      =
                new WebRequestState(webRequest, line);

            Write(state, url + " ");
            return(Task <WebResponse> .Factory.FromAsync(
                       webRequest.BeginGetResponse,
                       webRequest.EndGetResponse, state)
                   .ContinueWith(
                       (antecedent, antecedentState) =>
            {
                Stream stream =
                    antecedent.Result.GetResponseStream();
                using (StreamReader reader =
                           new StreamReader(stream))
                {
                    int length =
                        reader.ReadToEnd().Length;
                    Write(state,
                          FormatBytes(length).ToString());
                }
            }, state));
        }
 private static void Write(
     WebRequestState completedState, string text)
 {
     lock (ConsoleSyncObject)
     {
         Console.SetCursorPosition(
             completedState.ConsoleColumn,
             completedState.ConsoleLine);
         Console.Write(text);
         completedState.ConsoleColumn +=
             text.Length;
     }
 }
 private static void Write(
     WebRequestState completedState, string text)
 {
     lock(ConsoleSyncObject)
     {
         Console.SetCursorPosition(
             completedState.ConsoleColumn,
             completedState.ConsoleLine);
         Console.Write(text);
         completedState.ConsoleColumn +=
             text.Length;
     }
 }
        private static void DisplayProgress(WebRequestState state)
        {
            lock (ConsoleSyncObject)
            {
                int left = state.ConsoleColumn;
                int top  = state.ConsoleLine;
                if (left >= Console.BufferWidth -
                    int.MaxValue.ToString().Length)
                {
                    left = state.Url.Length;

                    Console.SetCursorPosition(left, top);
                    Console.Write("".PadRight(
                                      Console.BufferWidth - state.Url.Length));

                    state.ConsoleColumn = left;
                }

                Write(state, ".");
            }
        }
     DisplayPageSizeAsync(string url, int line)
 {
     WebRequest webRequest = WebRequest.Create(url);
     WebRequestState state =
         new WebRequestState(webRequest, line);
     Write(state, url + " ");
     return Task<WebResponse>.Factory.FromAsync(
             webRequest.BeginGetResponse,
             webRequest.EndGetResponse, state)
         .ContinueWith(
             (antecedent, antecedentState) =>
             {
                 Stream stream =
                     antecedent.Result.GetResponseStream();
                 using(StreamReader reader =
                     new StreamReader(stream))
                 {
                     int length =
                         reader.ReadToEnd().Length;
                     Write(state,
                         FormatBytes(length).ToString());
                 }
             }, state);
 }
        private static void DisplayProgress(WebRequestState state)
        {
            lock(ConsoleSyncObject)
            {
                int left = state.ConsoleColumn;
                int top = state.ConsoleLine;
                if(left >= Console.BufferWidth -
                    int.MaxValue.ToString().Length)
                {
                    left = state.Url.Length;

                    Console.SetCursorPosition(left, top);
                    Console.Write("".PadRight(
                        Console.BufferWidth - state.Url.Length));

                    state.ConsoleColumn = left;
                }

                Write(state, ".");
            }
        }