本文整理汇总了C#中Worker.RunWorkerAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Worker.RunWorkerAsync方法的具体用法?C# Worker.RunWorkerAsync怎么用?C# Worker.RunWorkerAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Worker
的用法示例。
在下文中一共展示了Worker.RunWorkerAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormLoader
public FormLoader(Plugin plugin, RecordReader stockReader, bool lazyLoading, int backgroundJobs)
{
if (backgroundJobs < 0)
throw new ArgumentException("Number of bakcground jobs must be a positive integer or zero");
sharedData = new SharedData()
{
Plugin = plugin,
StockReader = stockReader,
LazyLoading = lazyLoading,
FormsToLoad = new BlockingCollection<Form>(new ConcurrentQueue<Form>(), 1024),
WorkerCompleteEvent = new AutoResetEvent(false)
};
this.stockReader = stockReader;
asyncLoading = backgroundJobs > 0;
bool useStockReader = true;
while (backgroundJobs-- > 0)
{
Worker worker = new Worker(sharedData, useStockReader);
worker.RunWorkerCompleted += Worker_RunWorkerCompleted;
worker.RunWorkerAsync();
workers.Add(new WorkerInfo()
{
Worker = worker
});
// Only the first worker can use the stock reader
useStockReader = false;
}
}
示例2: UpdateList
//.........这里部分代码省略.........
Worker worker = new Worker(this, (cancelToken) =>
{
this.InvokeIfRequired(() =>
{
try
{
this.BeginUpdate();
this.Items.Clear();
}
finally
{
this.EndUpdate();
}
});
List<ListViewItem> items = new List<ListViewItem>();
if (this.MethodContainer is Class)
{
HashSet<string> got = new HashSet<string>();
foreach (Method m in this.MethodContainer.CalledMethods)
{
foreach (ThrownException ex in m.UnhandledExceptions)
{
if (this.Exceptions.Contains(ex))
{
string id = ex.Method.GetId() + ex.Exception.FullName;
if (!got.Contains(id))
{
got.Add(id);
//ListViewItem item = MakeItem(ex, ex.Method).Item;
ListViewItem item = MakeItem(ex, m).Item;
items.Add(item);
}
}
}
}
}
else if (this.GroupByType)
{
// group the exceptions by type
ThrownExceptionDictionary dict = new ThrownExceptionDictionary(this.Exceptions);
foreach (IEnumerable<ThrownException> list in dict.GetLists())
{
Type type = list.First().Exception;
ListViewGroup lvg = this.Groups.Add(type.FullName, type.Name);
list.ToList().ForEach(item => items.Add(MakeItem(item, item.Method, lvg).Item));
}
}
else
{
IEnumerable<Method> methods;
if (this.MethodContainer is Method)
{
}
else
{
methods = new Method[] { this.MethodContainer as Method }.Concat(this.MethodContainer.CalledMethods);
}
foreach (ThrownException ex in this.Exceptions)
{
Method m = null;
if (ex.Method == this.MethodContainer)
{
m = this.MethodContainer as Method;
}
else
{
m = this.MethodContainer.CalledMethods.FirstOrDefault(md => md.UnhandledExceptions.Contains(ex));
if (m == null)
{
m = this.MethodContainer as Method;
}
}
ListViewItem item = MakeItem(ex, m).Item;
items.Add(item);
}
}
this.InvokeIfRequired(() =>
{
try
{
this.BeginUpdate();
this.Items.AddRange(items.ToArray());
}
finally
{
this.EndUpdate();
}
});
});
worker.RunWorkerAsync();
}
示例3: showCalibrationForm
/// <summary>
/// Kicks off the background worker to display the calibration form
/// </summary>
/// <param name="position">where to display the form?</param>
/// <param name="caption">caption of the form</param>
/// <param name="prompt">any message to display?</param>
/// <param name="timeout">calibration timeout</param>
/// <param name="enableConfigure">should calibration button be enabled?</param>
private void showCalibrationForm(Windows.WindowPosition position, String caption, String prompt, int timeout, bool enableConfigure)
{
_bgTaskDoneEvent.Reset();
_bgWorker = new Worker
{
Prompt = prompt,
Timeout = timeout,
Caption = caption,
EnableConfigure = enableConfigure,
WorkerSupportsCancellation = true,
WorkerReportsProgress = false,
Position = position
};
_bgWorker.RunWorkerCompleted += bgWorker_RunCompleted;
_bgWorker.DoWork += bgWorker_DoWork;
_formCreatedEvent.Reset();
_bgWorker.RunWorkerAsync();
_formCreatedEvent.WaitOne();
}