public void UpdateEmptyRecycleBin()
        {
            Debug.WriteLine("UpdateEmptyRecycleBin");
            RecycleBinInfo info  = OS.GetAllRecycleBinInfo();
            string         label = "Empty Recycle Bins";

            if (info != null)
            {
                label += " (";
                if (info.ItemCount == 0 && info.Size == 0)
                {
                    label += "Empty";
                }
                else
                {
                    label += $"{info.ItemCount:N0} ";
                    if (info.ItemCount == 1)
                    {
                        label += $"Item";
                    }
                    else
                    {
                        label += $"Items";
                    }
                    label += $", {FormatBytes.Format(info.Size)}";
                }
                label += ")";
            }
            EmptyRecycleBinLabel = label;
            allRecycleBinInfo    = info;
            EmptyRecycleBin.RaiseCanExecuteChanged();
        }
        /// <summary>
        /// async-lambda
        /// </summary>
        private static void ShowTaskHighDelayAsync4()
        {
            string url = "http://www.IntelliTect.com";

            Console.Write(url);


            Func <string, Task> WriteWebRequestSizeAsync1 = async(WebUrl) =>
            {
                WebRequest  webRequest  = WebRequest.Create(WebUrl);
                WebResponse webResponse = await webRequest.GetResponseAsync();

                using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
                {
                    string text = await reader.ReadToEndAsync();

                    Console.WriteLine(FormatBytes.FormatBytesMethod(text.Length));
                }
            };

            Task task = WriteWebRequestSizeAsync1(url);

            while (!task.Wait(100))
            {
                Console.Write(".");
            }
        }
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     try {
         return(FormatBytes.Format(System.Convert.ToDouble(value)));
     }
     catch {
         return(null);
     }
 }
        private static async Task WriteWebRequestSizeAsync(string url)
        {
            WebRequest  webRequest  = WebRequest.Create(url);
            WebResponse webResponse = await webRequest.GetResponseAsync(); //(self) block -> (callstack thread) go on

            using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
            {
                string text = await reader.ReadToEndAsync();  //(self) block -> (callstack thread) go on

                Console.Write(FormatBytes.FormatBytesMethod(text.Length));
            }
        }
        private static void ShowTaskHighDelaySync()
        {
            //string url = "http://www.pandatv.com";
            string url = "http://www.IntelliTect.com";

            Console.Write(url);
            WebRequest webRequest = WebRequest.Create(url);

            WebResponse webResponse = webRequest.GetResponse();

            Console.Write("......");

            using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
            {
                string text = reader.ReadToEnd();
                Console.WriteLine(FormatBytes.FormatBytesMethod(text.Length));
            }
        }
Exemple #6
0
        private void UpdateEmptyRecycleBinThread()
        {
            Debug.WriteLine("UpdateEmptyRecycleBin");
            RecycleBinInfo info  = OS.GetAllRecycleBinInfo();
            string         label = "Empty Recycle Bins";

            if (info != null)
            {
                label += " (";
                if (info.ItemCount == 0 && info.Size == 0)
                {
                    label += "Empty";
                }
                else
                {
                    label += $"{info.ItemCount:N0} ";
                    if (info.ItemCount == 1)
                    {
                        label += $"Item";
                    }
                    else
                    {
                        label += $"Items";
                    }
                    label += $", {FormatBytes.Format(info.Size)}";
                }
                label += ")";
            }
            EmptyRecycleBinLabel = label;
            allRecycleBinInfo    = info;
            EmptyRecycleBin.RaiseCanExecuteChanged();
            if (lastRecycleWatch == null)
            {
                lastRecycleWatch = Stopwatch.StartNew();
            }
            else
            {
                lastRecycleWatch.Restart();
            }
        }
        /// <summary>
        /// asyncMethod
        /// </summary>
        private static void ShowTaskHighDelayAsync1()
        {
            string url = "http://www.IntelliTect.com";

            Console.Write(url);

            StreamReader reader     = null;
            WebRequest   webRequest = WebRequest.Create(url);
            Task         task       = webRequest.GetResponseAsync()
                                      .ContinueWith(FormerTask =>
            {
                WebResponse webResponse = FormerTask.Result;
                reader = new StreamReader(webResponse.GetResponseStream());
                return(reader.ReadToEndAsync());
            }).Unwrap()
                                      .ContinueWith(FormerTask =>
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                string text = FormerTask.Result;
                Console.Write(FormatBytes.FormatBytesMethod(text.Length));
            });

            try
            {
                while (!task.Wait(100))
                {
                    Console.Write(".");
                }
            }
            catch (AggregateException exception)
            {
            }
        }
        /// <summary>
        /// Task.run()  Factory.StartNew()->TaskCreationOptions.LongRunning
        /// </summary>
        private static void ShowTaskHighDelayAsync2()
        {
            string url = "http://www.IntelliTect.com";

            Console.Write(url);

            StreamReader reader     = null;
            WebRequest   webRequest = WebRequest.Create(url);

            //Task task = Task.Run(() =>
            //{
            //    WebResponse webResponse = webRequest.GetResponse();
            //    return webResponse;
            //}).ContinueWith(FormerTask =>
            //{
            //    reader = new StreamReader(FormerTask.Result.GetResponseStream());
            //    string text = reader.ReadToEnd();
            //    return text;
            //}).ContinueWith(FormerTask =>
            //{
            //    Console.Write(FormatBytes.FormatBytesMethod(FormerTask.Result.Length));
            //});


            //Task task = Task.Run(() =>
            //{
            //    WebResponse webResponse = webRequest.GetResponse();

            //    reader = new StreamReader(webResponse.GetResponseStream());
            //    string text = reader.ReadToEnd();

            //    Console.Write(FormatBytes.FormatBytesMethod(text.Length));
            //});

            /////////////////////// LongRunning ///////////////////////
            Task task = Task.Factory.StartNew(() =>
            {
                WebResponse webResponse = webRequest.GetResponse();

                reader      = new StreamReader(webResponse.GetResponseStream());
                string text = reader.ReadToEnd();

                Console.Write(FormatBytes.FormatBytesMethod(text.Length));
            }, TaskCreationOptions.LongRunning);



            try
            {
                /// Task Complete Event
                //task.GetAwaiter().OnCompleted(() =>
                //    {
                //        Console.WriteLine("Complete!");
                //    });


                while (!task.Wait(100))
                {
                    Console.Write(".");
                }
            }
            catch (AggregateException exception)
            {
            }
        }