本文整理汇总了C#中System.ComponentModel.BackgroundWorker.RunWorkerAsync方法的典型用法代码示例。如果您正苦于以下问题:C# System.ComponentModel.BackgroundWorker.RunWorkerAsync方法的具体用法?C# System.ComponentModel.BackgroundWorker.RunWorkerAsync怎么用?C# System.ComponentModel.BackgroundWorker.RunWorkerAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.BackgroundWorker
的用法示例。
在下文中一共展示了System.ComponentModel.BackgroundWorker.RunWorkerAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendRequest
public void SendRequest(string postRequest, Microsoft.Phone.Controls.PerformanceProgressBar performanceProgressBar)
{
var bw = new System.ComponentModel.BackgroundWorker();
bw.DoWork += (s, args) => // This runs on a background thread.
{
System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
{
performanceProgressBar.IsIndeterminate = true;
performanceProgressBar.Visibility = System.Windows.Visibility.Visible;
});
this.parameters = postRequest;
this.request = WebRequest.Create(new Uri("http://192.168.1.71:8080/MobileApplication/mythapi")) as WebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.BeginGetRequestStream(ReadCallback, request);
};
bw.RunWorkerCompleted += (s, args) =>
{
// Do your UI work here this will run on the UI thread.
// Clear progress bar.
performanceProgressBar.IsIndeterminate = false;
performanceProgressBar.Visibility = System.Windows.Visibility.Collapsed;
};
bw.RunWorkerAsync();
}
示例2: MyButton_Click
void MyButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
if (_worker != null)
{
_worker.CancelAsync();
_worker = null;
this.Content = _previousContent;
}
else if (MyOnClick != null)
{
_previousContent = this.Content;
_worker = new System.ComponentModel.BackgroundWorker();
_worker.WorkerSupportsCancellation = true;
_worker.WorkerReportsProgress = (MyOnProgress != null);
_worker.ProgressChanged += worker_ProgressChanged;
_worker.RunWorkerCompleted += worker_RunWorkerCompleted;
_worker.DoWork += delegate(object s, System.ComponentModel.DoWorkEventArgs args)
{
try
{
MyOnClick(this, _worker);
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.ToString(), ex.Message);
}
};
this.Content = "Cancel";
_worker.RunWorkerAsync();
}
}
示例3: CanTestContentsOfList
public void CanTestContentsOfList()
{
var worker = new System.ComponentModel.BackgroundWorker();
var list = new System.Collections.Generic.List<int>();
worker.RunWorkerCompleted += delegate { list.Add(1); };
worker.DoWork += delegate { Thread.Sleep(1); };
worker.RunWorkerAsync();
Assert.That(list, Has.Count.EqualTo(1).After(5000, 100));
}
示例4: 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;
}
};
}
示例5: CallRC
private void CallRC()
{
//Fix CE 3.6 /refresh command - Launch BackgroundWorker for DeleteDDS
System.ComponentModel.BackgroundWorker bw = new System.ComponentModel.BackgroundWorker();
bw.WorkerSupportsCancellation = true;
bw.WorkerReportsProgress = true;
bw.DoWork += new System.ComponentModel.DoWorkEventHandler(DeleteDDS);
bw.RunWorkerAsync();
Framework.CRYENGINE_RC_Call(m_convertedFilePath + " /refresh" + UserDialogCmd() + GetAdditionalCompressionPreset(), "File " + m_fileName + " succefully send to the Ressource Compiler at " + m_convertedFilePath);
}
示例6: btnDownload_Click
private void btnDownload_Click(object sender, RoutedEventArgs e)
{
startProgress();
model.getUrls();
bgWorker = new System.ComponentModel.BackgroundWorker();
bgWorker.WorkerReportsProgress = true;
bgWorker.DoWork += bgWorker_DoWork;
bgWorker.ProgressChanged += bgWorker_ProgressChanged;
bgWorker.RunWorkerCompleted += bgWorker_RunWorkerCompleted;
bgWorker.RunWorkerAsync();
}
示例7: button_Click
private void button_Click(object sender, RoutedEventArgs e)
{
CNbutton.Visibility = Visibility.Hidden;
bw = new System.ComponentModel.BackgroundWorker();
bw.DoWork += Bw_DoWork;
bw.ProgressChanged += Bw_ProgressChanged;
bw.RunWorkerCompleted += Bw_RunWorkerCompleted;
bw.WorkerReportsProgress = true;
bw.RunWorkerAsync();
//ThreadPool.
//Thread thread = new Thread(UpdateTextRight);
////thread.s
//thread.Start();
}
示例8: StartAsyncSilent
private static void StartAsyncSilent(Action complete, Action work)
{
System.ComponentModel.BackgroundWorker bg = new System.ComponentModel.BackgroundWorker();
bg.DoWork += (s, e) =>
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
work();
};
if (complete != null)
bg.RunWorkerCompleted += (s, e) => complete();
bg.RunWorkerAsync();
}
示例9: Background
/// <summary>
/// Runs action in a BackgroundWorker, waits until complete and calls DoEvents every 100 milliseconds
/// </summary>
/// <remarks>
/// This is handy for running a long-timed-thing and keep the forms alive while it runs.
/// Be careful, users can do weird things while you are away.
/// </remarks>
/// <param name="aAction">What to run</param>
public static void Background(Action aAction)
{
using (System.ComponentModel.BackgroundWorker bgw = new System.ComponentModel.BackgroundWorker())
{
bgw.DoWork += new System.ComponentModel.DoWorkEventHandler(
delegate(object sender, System.ComponentModel.DoWorkEventArgs e)
{
aAction();
});
bgw.RunWorkerAsync();
while (bgw.IsBusy)
{
System.Windows.Forms.Application.DoEvents();
System.Threading.Thread.Sleep(100);
}
}
}
示例10: start
void start()
{
debug("starting setup...");
s = new TLServer_IP(IPUtil.LOCALHOST, IPUtil.TLDEFAULTTESTPORT, 0, 100000);
s.VerboseDebugging = true;
s.SendDebugEvent += new DebugDelegate(debug);
s.newProviderName = Providers.TradeLink;
s.Start(5,200,true);
Assert.IsTrue(s.isStarted);
// make sure we select our own loopback, if other servers are running
c = new TLClient_IP(TLClient_IP.GetEndpoints(s.Port,new string[] { System.Net.IPAddress.Loopback.ToString() }),0,"tlclient",0,0,debugc,true);
c.VerboseDebugging = true;
// create a second client to verify order and fill copying work
//c2 = new TLClient_IP(TLClient_IP.GetEndpoints(IPUtil.TLDEFAULTTESTPORT, new string[] { System.Net.IPAddress.Loopback.ToString() }), 0, "tlclient2", 0, 0, debug);
// register server events (so server can process orders)
s.newSendOrderRequest += new OrderDelegateStatus(tl_gotSrvFillRequest);
// setup client events
c.gotFill += new FillDelegate(tlclient_gotFill);
c.gotOrder += new OrderDelegate(tlclient_gotOrder);
c.gotTick += new TickDelegate(tlclient_gotTick);
c.gotImbalance += new ImbalanceDelegate(c_gotImbalance);
c.gotFeatures += new MessageTypesMsgDelegate(c_gotFeatures);
c.GotConnectEvent += new Int32Delegate(c_GotConnectEvent);
c.GotDisconnectEvent += new Int32Delegate(c_GotDisconnectEvent);
// setup second client events to check copying
//c2.gotFill += new FillDelegate(c2_gotFill);
//c2.gotOrder += new OrderDelegate(c2_gotOrder);
//c2.gotTick += new TickDelegate(c2_gotTick);
debug("ending setup.");
startt = DateTime.Now;
// prepare to playback ticks continuously
bw = new System.ComponentModel.BackgroundWorker();
bw.DoWork += new System.ComponentModel.DoWorkEventHandler(bw_DoWork);
bw.RunWorkerAsync();
debug("waiting for helper to start...");
while (!_looping)
sleep(50);
}
示例11: Send
public Send()
{
InitializeComponent();
try
{
System.ComponentModel.BackgroundWorker bw = new System.ComponentModel.BackgroundWorker();
bw.DoWork += new System.ComponentModel.DoWorkEventHandler(bw_DoWork);
bw.RunWorkerAsync();
}
catch (Exception ex)
{
while (ex != null)
{
MessageBox.Show(ex.Message);
ex = ex.InnerException;
}
}
}
开发者ID:hugonjerome,项目名称:CSharp-4-Developpez-des-applications-Windows-avec-Visual-Studio-2010,代码行数:18,代码来源:Send.cs
示例12: 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();
}
示例13: parseFile
private void parseFile()
{
IntelluaSource source = new IntelluaSource(this, true);
m_worker = new System.ComponentModel.BackgroundWorker();
FileParser fp = new FileParser(source);
/*fp.doWork(this,new System.ComponentModel.DoWorkEventArgs(0));
m_autoCompleteData = fp.result;*/
m_worker.DoWork += new System.ComponentModel.DoWorkEventHandler(fp.doWork);
m_worker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(parseFileDone);
m_worker.RunWorkerAsync();
}
示例14: Downloader
public Downloader(String source)
{
this.source = source;
downloader_bg = new System.ComponentModel.BackgroundWorker();
downloader_bg.DoWork += new System.ComponentModel.DoWorkEventHandler(downloader_bg_DoWork);
downloader_bg.RunWorkerAsync();
}
示例15: InitializeSpectrogram
/////////////////////////////////////////////////
public void InitializeSpectrogram(string spectrogramDirectory)
{
_spectrogramBitmaps = new List<Bitmap>();
_tempShowSpectrogram = ShowSpectrogram;
ShowSpectrogram = false;
if (Directory.Exists(spectrogramDirectory))
{
_spectrogramDirectory = spectrogramDirectory;
var bw = new System.ComponentModel.BackgroundWorker();
bw.DoWork += LoadSpectrogramBitmapsAsync;
bw.RunWorkerCompleted += LoadSpectrogramBitmapsCompleted;
bw.RunWorkerAsync();
}
}