本文整理汇总了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;
}
}
示例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);
}
}
示例3: StartAsync
public static void StartAsync(Action a)
{
BackgroundWorker bg = new BackgroundWorker();
bg.DoWork += delegate { a(); };
bg.RunWorkerCompleted += delegate { bg.Dispose(); };
bg.RunWorkerAsync();
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
};
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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();
}