コード例 #1
0
        private void btnClean_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                Task <LinkedList <string> > t = Task <LinkedList <string> > .Run(() => WorkSpace.Clean(folderBrowserDialog1.SelectedPath));

                try
                {
                    t.Wait();
                    if (t.IsCompleted)
                    {
                        LinkedList <string> _finallist = t.Result;
                        if (_finallist != null && _finallist.Count > 0)
                        {
                            SetText("\nThe below directories were cleanedup:");
                            foreach (string _ff in _finallist)
                            {
                                SetText(String.Format("\n{0}", _ff));
                            }
                        }
                        else
                        {
                            SetText("\nNo directory found empty!!");
                        }
                    }
                    SetText("\nCleanup completed successfully!!");
                }
                catch (AggregateException aex)
                {
                    // Assume we know what's going on with this particular exception.
                    // Rethrow anything else. AggregateException.Handle provides
                    // another way to express this. See later example.
                    foreach (Exception ex in aex.InnerExceptions)
                    {
                        // log the exceptions
                        Logger.Write("Log exception caused due to : {0}", ex.ToString());
                    }
                }
            }
        }