本文整理汇总了C#中BackgroundWorker.RunWorkerAsync方法的典型用法代码示例。如果您正苦于以下问题:C# BackgroundWorker.RunWorkerAsync方法的具体用法?C# BackgroundWorker.RunWorkerAsync怎么用?C# BackgroundWorker.RunWorkerAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BackgroundWorker
的用法示例。
在下文中一共展示了BackgroundWorker.RunWorkerAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: bgworkercounter
public void bgworkercounter()
{
var backgroundWorker1 = new BackgroundWorker();
backgroundWorker1.DoWork += backgroundWorker1_DoWork;
backgroundWorker1.RunWorkerCompleted += backgroundWorker1_RunWorkerCompleted;
backgroundWorker1.RunWorkerAsync();
}
示例2: Main
// private static SimpleCompileForm _simpleCompileForm;
private static void Main(string[] args)
{
var worker = new BackgroundWorker();
worker.DoWork += (sender, e) =>
{
try
{
_nativeWorkbenchForm = new NativeWorkbenchForm();
_timer = new System.Windows.Forms.Timer();
_timer.Stop();
_timer.Interval = 100;
_timer.Tick += _timer_Tick;
_timer.Start();
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
Application.EnableVisualStyles();
Application.Run(_nativeWorkbenchForm);
};
worker.RunWorkerAsync();
Thread.Sleep(-1);
}
示例3: Start
// Use this for initialization
void Start()
{
// init a background worker thread
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += HandleWorkerDoWork;
worker.RunWorkerAsync();
}
示例4: NativeWorkbench
public NativeWorkbench()
{
try
{
// KeyDown += OnKeyDown;
Tick += OnTick;
}
catch (Exception e)
{
SaveLoad.Log(e.ToString());
// Debug.WriteLine(e);
}
BackgroundWorker myWorker = new BackgroundWorker();
myWorker.DoWork += (sender, e) =>
{
try
{
Application.EnableVisualStyles();
Application.Run(_nativeWorkbenchForm);
}
catch (Exception ex)
{
SaveLoad.Log(ex.ToString());
}
};
myWorker.RunWorkerAsync();
}
示例5: TestCancelAsync
public void TestCancelAsync()
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += DoWorkExpectCancel;
bw.WorkerSupportsCancellation = true;
manualResetEvent3 = new ManualResetEventSlim(false);
bw.RunWorkerAsync("Message");
bw.CancelAsync();
bool ret = manualResetEvent3.Wait(TimeoutLong);
Assert.True(ret);
// there could be race condition between worker thread cancellation and completion which will set the CancellationPending to false
// if it is completed already, we don't check cancellation
if (bw.IsBusy) // not complete
{
if (!bw.CancellationPending)
{
for (int i = 0; i < 1000; i++)
{
Wait(TimeoutShort);
if (bw.CancellationPending)
{
break;
}
}
}
// Check again
if (bw.IsBusy)
Assert.True(bw.CancellationPending, "Cancellation in Main thread");
}
}
示例6: ThrowExceptionOnCompletedFalse
public void ThrowExceptionOnCompletedFalse()
{
var b = new BackgroundWorker<object, object, object>
{
ThrowExceptionOnCompleted = false,
DoWork = ThrowException
};
b.RunWorkerAsync();
}
示例7: Worker
public Worker(string[] arguments)
{
this.worker = new BackgroundWorker();
worker.WorkerSupportsCancellation = true;
worker.WorkerReportsProgress = true;
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
worker.RunWorkerAsync(arguments);
}
示例8: FFRKMySqlInstance
public FFRKMySqlInstance()
{
mDatabaseThread = new BackgroundWorker();
mDatabaseThread.DoWork += mDatabaseThread_DoWork;
mDatabaseThread.RunWorkerAsync();
mDatabaseQueue = new BlockingCollection<IDbRequest>();
mCancellationTokenSource = new CancellationTokenSource();
mConnectionState = ConnectionState.Disconnected;
}
示例9: FileState
public FileState()
: base()
{
asyncWriter = new BackgroundWorker();
asyncWriter.DoWork += new DoWorkEventHandler(WriteDataAsync);
asyncWriter.RunWorkerCompleted +=
new RunWorkerCompletedEventHandler(
(object sender, RunWorkerCompletedEventArgs e) => { if (postponedWrite) { postponedWrite = false; asyncWriter.RunWorkerAsync(); } }
);
}
示例10: TestBackgroundWorkerBasic
public void TestBackgroundWorkerBasic()
{
var orignal = SynchronizationContext.Current;
try
{
SynchronizationContext.SetSynchronizationContext(null);
const int expectedResult = 42;
const int expectedReportCallsCount = 5;
int actualReportCallsCount = 0;
var worker = new BackgroundWorker() { WorkerReportsProgress = true };
var progressBarrier = new Barrier(2, barrier => ++actualReportCallsCount);
var workerCompletedEvent = new ManualResetEventSlim(false);
worker.DoWork += (sender, e) =>
{
for (int i = 0; i < expectedReportCallsCount; i++)
{
worker.ReportProgress(i);
progressBarrier.SignalAndWait();
}
e.Result = expectedResult;
};
worker.RunWorkerCompleted += (sender, e) =>
{
try
{
Assert.Equal(expectedResult, (int)e.Result);
Assert.False(worker.IsBusy);
}
finally
{
workerCompletedEvent.Set();
}
};
worker.ProgressChanged += (sender, e) =>
{
progressBarrier.SignalAndWait();
};
worker.RunWorkerAsync();
// wait for singal from WhenRunWorkerCompleted
Assert.True(workerCompletedEvent.Wait(TimeoutLong));
Assert.False(worker.IsBusy);
Assert.Equal(expectedReportCallsCount, actualReportCallsCount);
}
finally
{
SynchronizationContext.SetSynchronizationContext(orignal);
}
}
示例11: Run
public void Run()
{
worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(DoWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(RunWorkerCompleted);
worker.ProgressChanged += new ProgressChangedEventHandler(ProgressChanged);
worker.WorkerReportsProgress = true;
worker.WorkerSupportsCancellation = true;
worker.RunWorkerAsync(Options);
}
示例12: SendTransform
void SendTransform()
{
var pos = transform.position;
var angles = transform.localEulerAngles;
var worker = new BackgroundWorker();
var time = Time.time;
worker.DoWork += (sender, e) => {
ISFSObject obj = NetworkHelper.TransformToSFSObject(pos, angles);
obj.PutBool("isBlue", IsBlueTeam);
obj.PutFloat("time", time);
smartFox.Send(new ObjectMessageRequest(obj));
};
worker.RunWorkerAsync();
}
示例13: RunInBackgroundOrNot
void RunInBackgroundOrNot(Action action)
{
if (runInSeparateThread) {
var worker = new BackgroundWorker ();
worker.DoWork += delegate(object sender, DoWorkEventArgs e) {
action ();
};
worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) {
Debug.Log ("Background thread done");
};
worker.RunWorkerAsync ();
} else {
action ();
Debug.Log ("Done");
}
}
示例14: wireless_devices
public wireless_devices(AdminWindow w)
{
mainform = w;
AddDevice = new RelayCommand(o => SecuredDevices.Add(o as WirelessDevice), o => (o != null && (SecuredDevices.Count <= 1)));
RemoveDevice = new RelayCommand(o => SecuredDevices.Remove(o as WirelessDevice), o => o != null);
InitializeComponent();
WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
//initialiseLoggingFramework();
log = Logger.Instance;
bg = new BackgroundWorker();
bg.DoWork += new DoWorkEventHandler(bg_DoWork);
bg.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bg_RunWorkerCompleted);
if (!bg.IsBusy)
{
bg.RunWorkerAsync();
}
}
示例15: POSPageViewModel
public POSPageViewModel()
{
this.SaleCommand = new Telerik.Windows.Controls.DelegateCommand(o => this.methodSaleCommand());
MyImageButtonCatagories = new ObservableCollection<MyImageButtonCatagory>();
BackgroundWorker imageButtonsCataogryWorker = new BackgroundWorker();
imageButtonsCataogryWorker.DoWork += new DoWorkEventHandler(imageButtonsCatagoryWorker_DoWork);
imageButtonsCataogryWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(imageButtonsCatagoryWorker_runworkercompleted);
imageButtonsCataogryWorker.RunWorkerAsync();
this._eventAggregator.GetEvent<AmountEnteredEvent>()
.Subscribe((eventDetail) =>
{
logger.Trace("event received {0}", eventDetail.Id);
userEnterAmount(double.Parse(eventDetail.Detail));
});
}