本文整理汇总了C#中System.ComponentModel.BackgroundWorker.CancelAsync方法的典型用法代码示例。如果您正苦于以下问题:C# System.ComponentModel.BackgroundWorker.CancelAsync方法的具体用法?C# System.ComponentModel.BackgroundWorker.CancelAsync怎么用?C# System.ComponentModel.BackgroundWorker.CancelAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.BackgroundWorker
的用法示例。
在下文中一共展示了System.ComponentModel.BackgroundWorker.CancelAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportingDialog
public ExportingDialog(iMetaLibrary.Scanners.MovieScanner MovieScanner, iMetaLibrary.Scanners.TvScanner TvScanner)
{
this.Build ();
notebook1.ShowTabs = false;
notebook1.ShowBorder = false;
bkgWorker = new System.ComponentModel.BackgroundWorker();
bkgWorker.WorkerSupportsCancellation = true;
bkgWorker.DoWork += HandleBkgWorkerDoWork;
System.Timers.Timer pulsar = new System.Timers.Timer(50) { AutoReset = true};
pulsar.Elapsed += delegate {
pbarExporting.Pulse();
};
this.buttonCancel.Clicked += delegate(object sender, EventArgs e)
{
bkgWorker.CancelAsync();
this.Destroy();
};
this.buttonOk.Clicked += delegate(object sender, EventArgs e) {
if(notebook1.Page == 0)
{
string folder = filechooserbutton1.Filename;
if(String.IsNullOrEmpty(folder) || !System.IO.Directory.Exists(folder)){
MessageBox.Show("Invalid export location specfied.");
return;
}
this.buttonOk.Visible = false;
bkgWorker.RunWorkerAsync(new object[] { folder, MovieScanner, TvScanner} );
pulsar.Start();
notebook1.Page = 1;
}
else
{
// final page.
this.Destroy();
}
};
bkgWorker.RunWorkerCompleted += delegate(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) {
pulsar.Stop();
if(e.Result as bool? == true)
{
notebook1.Page = 2;
this.buttonOk.Visible = true;
this.buttonCancel.Visible = false;
}
else
{
notebook1.Page = 3;
this.buttonOk.Visible = true;
this.buttonCancel.Visible = false;
}
};
}
示例2: Run
public void Run()
{
System.ComponentModel.BackgroundWorker bw = new System.ComponentModel.BackgroundWorker();
bw.DoWork += new System.ComponentModel.DoWorkEventHandler(bw_DoWork);
bw.RunWorkerAsync();
try
{
System.Net.WebClient myClient = new System.Net.WebClient();
myClient.DownloadFile(update_location + updated_file, local_updated_file);
myClient.DownloadFile(update_location + updater, updater);
System.IO.FileInfo exe = new System.IO.FileInfo(System.Windows.Forms.Application.ExecutablePath);
String param = "\"" + exe.Name + "\" " + "\"" + local_updated_file + "\"";
System.Diagnostics.Process.Start(updater, param);
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
}
bw.CancelAsync();
}
示例3: RawPerformanceWithLoad
public void RawPerformanceWithLoad()
{
System.ComponentModel.BackgroundWorker bw = new System.ComponentModel.BackgroundWorker();
bw.DoWork += new System.ComponentModel.DoWorkEventHandler(bw_DoWork);
bw.WorkerSupportsCancellation = true;
MultiSimImpl h = new MultiSimImpl(Environment.CurrentDirectory);
rawbase("raw performance multi w/load", 3, h);
// tick count is = 42610 (FTI) + 5001 (SPX) + 8041 (ABN)
Assert.AreEqual(42610 + 4991 + 8041, tickcount);
// check running time
Assert.LessOrEqual(h.RunTimeSec, EXPECTRAW, "may fail on slow machines");
// last time is 1649 on SPX
Assert.AreEqual(20080318155843, lasttime);
RawPerformance();
bw.CancelAsync();
run = false;
// tick count is = 42610 (FTI) + 5001 (SPX) + 8041 (ABN)
Assert.AreEqual(42610 + 4991 + 8041, tickcount);
// check running time
Assert.LessOrEqual(h.RunTimeSec, EXPECTRAW, "may fail on slow machines");
// last time is 1649 on SPX
Assert.AreEqual(20080318155843, lasttime);
}