当前位置: 首页>>代码示例>>C#>>正文


C# BackgroundWorker.Dispose方法代码示例

本文整理汇总了C#中System.ComponentModel.BackgroundWorker.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# BackgroundWorker.Dispose方法的具体用法?C# BackgroundWorker.Dispose怎么用?C# BackgroundWorker.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ComponentModel.BackgroundWorker的用法示例。


在下文中一共展示了BackgroundWorker.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AsyncCommandBinding

        public AsyncCommandBinding(ICommand command, ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute, RunWorkerCompletedEventHandler runWokrerCompleted)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            _task = new BackgroundWorker();
            _task.DoWork += delegate
                                {
                                    executed(null, null);
                                };
            _task.RunWorkerCompleted += (s, e) =>
                                            {
                                                runWokrerCompleted(s, e);
                                                _task.Dispose();
                                            };

            Command = command;
            if (executed != null)
            {
                Executed += delegate
                                {
                                    if (!_task.IsBusy)
                                        _task.RunWorkerAsync();
                                };
            }
            if (canExecute != null)
            {
                CanExecute += canExecute;
            }
        }
开发者ID:Mrding,项目名称:Ribbon,代码行数:32,代码来源:AsyncCommandBinding.cs

示例2: BindList

        private void BindList()
        {
            try
            {
                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += (o, ea) =>
                {
                    if (list == null)
                    {
                        list = new List<DataModel.TranslationEntryDiff>();
                        list = transManage.GetDiffStrings();
                        searchList = list;
                    }
                    Dispatcher.Invoke(new Action(() => gvList.ItemsSource = searchList));
                };

                worker.RunWorkerCompleted += (o, ea) =>
                {
                    pBar.Visibility = Visibility.Hidden;
                    worker.Dispose();
                };

                SetStatusLabelValue(tsslblException, "");
                pBar.Visibility = Visibility.Visible;
                worker.RunWorkerAsync();
            }
            catch(Exception ex)
            {
                SetStatusLabelValue(tsslblException, ex.Message);
            }
        }
开发者ID:nijunjie,项目名称:UITextTransRepo,代码行数:31,代码来源:frmDiffString.xaml.cs

示例3: StartAsync

 public static void StartAsync(Action a)
 {
     BackgroundWorker bg = new BackgroundWorker();
     bg.DoWork += delegate { a(); };
     bg.RunWorkerCompleted += delegate { bg.Dispose(); };
     bg.RunWorkerAsync();
 }
开发者ID:AlphaDelta,项目名称:Midori-Desktop,代码行数:7,代码来源:Async.cs

示例4: RunWorkerAsync

 /// <summary>
 /// Starts execution of a background operation.
 /// </summary>
 /// <param name="action">The operation to be invoked by a <see cref="System.ComponentModel.BackgroundWorker"/>.</param>
 public static void RunWorkerAsync(Action<object, DoWorkEventArgs> action)
 {
     var w = new BackgroundWorker();
     w.DoWork += (s, e) => action(s, e);
     w.RunWorkerCompleted += (s, e) => w.Dispose();
     w.RunWorkerAsync();
 }
开发者ID:piquant,项目名称:AbsyntaxExcelAddIn,代码行数:11,代码来源:SelfDisposingBackgroundWorker.cs

示例5: search_Click

 private void search_Click(object sender, EventArgs e)
 {
     BackgroundWorker bgWorker = new BackgroundWorker();
     bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);
     bgWorker.RunWorkerAsync();
     bgWorker.Dispose();
     search.Enabled = false;
 }
开发者ID:rew170,项目名称:soomecode,代码行数:8,代码来源:Form1.cs

示例6: MyToolWindow_Loaded

        private void MyToolWindow_Loaded(object sender, RoutedEventArgs e)
        {
            if (_loaded) return;
            var overflowGrid = explorerToolbar.Template.FindName("OverflowGrid", explorerToolbar) as FrameworkElement;
            if (overflowGrid != null)
            {
                overflowGrid.Visibility = Visibility.Collapsed;
            }
            //explorerToolbar.Foreground = Helpers.VSThemes.GetWindowText();
            //explorerToolbar.Background = Helpers.VSThemes.GetCommandBackground();
            //toolTray.Background = explorerToolbar.Background;
            //sep2.Background = sep1.Background = Helpers.VSThemes.GetToolbarSeparatorBackground();
            TreeView1.Background = grid1.Background = Helpers.VSThemes.GetToolWindowBackground();
            Updated.Visibility = System.Windows.Visibility.Collapsed;

            // Look for update async
            BackgroundWorker bw = new BackgroundWorker();
            bw.DoWork += new DoWorkEventHandler(bw_DoWork);
            bw.RunWorkerCompleted += (s, ea) =>
            {
                try
                {
                    if ((Boolean)ea.Result == true)
                    {
                        Updated.Visibility = System.Windows.Visibility.Visible;
                        myStoryboard.Begin(this);
                    }
                    else
                    {
                        Updated.Visibility = System.Windows.Visibility.Collapsed;
                    }
                }
                finally
                {
                    bw.Dispose();
                }
            };

            // Animate updated button
            DoubleAnimation myDoubleAnimation = new DoubleAnimation();
            myDoubleAnimation.From = 0.1;
            myDoubleAnimation.To = 1.0;
            myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));
            myDoubleAnimation.AutoReverse = true;
            myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;

            myStoryboard = new Storyboard();
            myStoryboard.Children.Add(myDoubleAnimation);
            Storyboard.SetTargetName(myDoubleAnimation, UpdatedText.Name);
            Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(TextBlock.OpacityProperty));
            BuildDatabaseTree();
            bw.RunWorkerAsync();
            AddHandler(Keyboard.KeyDownEvent, (KeyEventHandler)HandleKeyDownEvent);
            txtConnections.Focus();
            _loaded = true;
        }
开发者ID:inickvel,项目名称:SqlCeToolbox,代码行数:56,代码来源:ExplorerControl.xaml.cs

示例7: DocumentUploader

        public DocumentUploader()
        {
            InitializeComponent();

            CmsWebService service = new CmsWebService();

            WindowsIdentity windowsUser = WindowsIdentity.GetCurrent();
            if (windowsUser == null)
            {
                return;
            }

            List<string> temp = windowsUser.Name.Split('\\').ToList();
            User user = service.GetUser(temp.Last());

            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["CmsEntities"];
            EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder(settings.ConnectionString);
            SqlConnectionStringBuilder conn = new SqlConnectionStringBuilder(builder.ProviderConnectionString);

            lblTitle.Text = string.Format("Document Version Imports: by {0} into {1} on {2}", user.UserName, conn.InitialCatalog, conn.DataSource);

            mMetaData.UserId = user.Id;
            using (mWorker = new BackgroundWorker())
            {
                mWorker.WorkerSupportsCancellation = true;
                mWorker.WorkerReportsProgress = true;
                mWorker.ProgressChanged += bw_ProgressChanged;
                mWorker.RunWorkerCompleted += bw_RunWorkerCompleted;

                mWorker.DoWork += (s1, e1) =>
                    {
                        try
                        {
                            if (mWorker.CancellationPending)
                            {
                                mWorker.CancelAsync();
                                mWorker.Dispose();
                            }
                            else
                            {
                                //WORK
                                ImportDocuments(mWorker);
                            }
                        }
                        catch (ThreadAbortException)
                        {
                            Thread.ResetAbort();
                        }
                    };
            }
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:51,代码来源:DocumentUploader.cs

示例8: buttonValidate_Click

        private void buttonValidate_Click(object sender, EventArgs e)
        {
            var doValidate = MessageBox.Show("SnakeBite will close the Steam validation window automatically when ready, please do not cancel or close the Steam window.", "SnakeBite", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (doValidate == DialogResult.Cancel) return;
            System.Diagnostics.Process.Start("steam://validate/287700/");
            BackgroundWorker bw = new BackgroundWorker();
            bw.DoWork += (obj, var) =>
            {
                int sleep = 0;
                int maxSleep = 7500;
                while (true)
                {
                    System.Threading.Thread.Sleep(100);
                    sleep += 100;

                    if(!BackupManager.GameFilesExist()) // break when files are removed by Steam
                    {
                        try
                        {
                            Microsoft.VisualBasic.Interaction.AppActivate("Validating Steam files");
                            SendKeys.SendWait("%{F4}");
                        }
                        catch
                        {
                            MessageBox.Show("Unable to locate and close the Steam window, you may need to launch Steam before trying again, or validate manually through the Steam application.", "Steam Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        break;
                    }

                    if (sleep >= maxSleep) // break on timeout
                    {
                        try
                        {
                            Microsoft.VisualBasic.Interaction.AppActivate("Validating Steam files");
                            SendKeys.SendWait("%{F4}");
                        }
                        catch
                        {
                            MessageBox.Show("Timed out waiting for Steam window. Please launch Steam before trying again, or validate manually through the Steam application.", "Steam Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        break;
                    }
                }

                bw.Dispose();
            };
            bw.RunWorkerAsync();
            BackupManager.DeleteOriginals();
        }
开发者ID:topher-au,项目名称:SnakeBite,代码行数:49,代码来源:FindInstallPage.cs

示例9: importBtn_Click

 private void importBtn_Click(object sender, EventArgs e)
 {
     string SelectExcelFile = filePath.Text;
     if (string.IsNullOrEmpty(SelectExcelFile))
     {
         errorMsg.Text = "Excel文件不能为空!";
         return;
     }
     this.importBtn.Enabled = false;
     this.pictureBox1.Visible = true;
     BackgroundWorker worker = new BackgroundWorker();
     worker.DoWork += new DoWorkEventHandler(worker_DoWork);
     worker.RunWorkerAsync();
     worker.Dispose();
 }
开发者ID:rew170,项目名称:soomecode,代码行数:15,代码来源:ExcelImpForm.cs

示例10: Kill

 public static void Kill(object parameter)
 {
     BackgroundWorker worker = new BackgroundWorker();
     worker.DoWork += async (sender, args) =>
     {
         var textBlock = parameter as TextBlock;
         if (textBlock != null)
             await textBlock.Dispatcher.InvokeAsync(async () =>
             {
                 FastbootTools.Kill();
                 await textBlock.Dispatcher.InvokeAsync(() => textBlock.Text = "FASTBOOT KILLED");
             });
     };
     worker.RunWorkerCompleted += (sender, args) => worker.Dispose();
     worker.RunWorkerAsync();
 }
开发者ID:pzlatjava,项目名称:Android-ToolkitV2,代码行数:16,代码来源:FastbootPresenter.cs

示例11: Prepare

 public static void Prepare(object parameter)
 {
     BackgroundWorker worker = new BackgroundWorker();
     worker.DoWork += async (sender, args) =>
     {
         var textBlock = parameter as TextBlock;
         if (textBlock != null)
             await textBlock.Dispatcher.InvokeAsync(async () =>
             {
                 Fastboot = new FastbootTools(textBlock);
                 await Fastboot.Prepare();
             });
     };
     worker.RunWorkerCompleted += (sender, args) => worker.Dispose();
     worker.RunWorkerAsync();
 }
开发者ID:pzlatjava,项目名称:Android-ToolkitV2,代码行数:16,代码来源:FastbootPresenter.cs

示例12: Show

        public static void Show(string WindowTitle, string ProgressText, Action WorkerFunction)
        {
            var progressWindow = new formProgress();
            progressWindow.StatusText.Text = ProgressText;

            var progressWorker = new BackgroundWorker();
            progressWorker.DoWork += (obj, var) =>
            {
                WorkerFunction();
                progressWindow.Invoke((MethodInvoker)delegate { progressWindow.Close(); });
                progressWorker.Dispose();
            };

            progressWorker.RunWorkerAsync();
            progressWindow.ShowDialog();
        }
开发者ID:topher-au,项目名称:SnakeBite,代码行数:16,代码来源:ProgressWindow.cs

示例13: path_DoubleClick

 public void path_DoubleClick(object sender, MouseButtonEventArgs e)
 {
     FolderBrowserDialog way = new FolderBrowserDialog();
     DialogResult result = way.ShowDialog();
     if (result == System.Windows.Forms.DialogResult.OK)
     {
         path.Text = way.SelectedPath;
         picName = (Directory.GetFiles(path.Text, "*jpg")).ToList();
         ShowImage(picName[0]);
         progress.Value = 0;
         progress.Maximum = picName.Count;
         bw = new BackgroundWorker();
         bw.WorkerReportsProgress = true;
         bw.DoWork += bw_DoWork;
         bw.ProgressChanged += bw_ProgressChanged;
         bw.RunWorkerAsync();
         bw.Dispose();
     }
 }
开发者ID:nenravitsa,项目名称:picture-view,代码行数:19,代码来源:MainWindow.xaml.cs

示例14: ExecuteListDevices

 public static void ExecuteListDevices(object parameter)
 {
     UIParameters parameters = (UIParameters)parameter;
     if (parameters != null)
     {
         Context = parameters.Context;
         BackgroundWorker worker = new BackgroundWorker();
         worker.DoWork += async (sender, args) =>
         {
             await Context.Dispatcher.InvokeAsync(async () =>
             {
                 _adb = new AdbTools(Context);
                 await _adb.ListDevices(parameters.Context2, parameters.Bool);
             });
         };
         worker.RunWorkerCompleted += (sender, args) => worker.Dispose();
         worker.RunWorkerAsync();
     }
 }
开发者ID:pzlatjava,项目名称:Android-ToolkitV2,代码行数:19,代码来源:AdbPresenter.cs

示例15: Window_Loaded

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            lblPath.Text = ConfigurationManager.AppSettings["PathOnNova"].ToString();
            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += (o, ea) =>
            {
                for (int i = 10; i > 0; i--)
                {
                    Thread.Sleep(1000);
                    ChangeButtonText(btnClose, "Close after " + (i - 1).ToString() + " seconds");
                }
            };

            worker.RunWorkerCompleted += (o, ea) =>
            {
                Application.Current.Shutdown();
                worker.Dispose();
            };
            worker.RunWorkerAsync();
        }
开发者ID:nijunjie,项目名称:LaunchSCCMUIRespository,代码行数:20,代码来源:frmBlock.xaml.cs


注:本文中的System.ComponentModel.BackgroundWorker.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。