关闭 BackgroundWorker 长时间单任务的方式

        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            var thisWorker = sender as BackgroundWorker;

            //var _child = new Thread(() =>
            //{
            //    try
            //    {
            //        var responseResult = PostFile(SelectedFilePath);
            //        //System.Threading.Thread.Sleep(30000);

            //        //GC.Collect();
            //    }
            //    catch (Exception ex)
            //    {
            //        throw;
            //    }

            //});
            //_child.Start();

            //while (_child.IsAlive)
            //{
            //    if (thisWorker.CancellationPending)
            //    {
            //        _child.Abort();
            //        e.Cancel = true;
            //    }
            //    System.Threading.Thread.Sleep(500);
            //}
        }

No Comments

Add a Comment