向背景工作者发送参数?

向背景工作者发送参数?,第1张

背景工作者发送参数?

您可以这样启动:

int value = 123;bgw1.RunWorkerAsync(argument: value);  // the int will be boxed

然后

private void worker_DoWork(object sender, DoWorkEventArgs e) {   int value = (int) e.Argument;   // the 'argument' parameter resurfaces here   ...   // and to transport a result back to the main thread   double result = 0.1 * value;   e.Result = result;}// the Completed handler should follow this pattern // for Error and (optionally) Cancellation handlingprivate void worker_Completed(object sender, RunWorkerCompletedEventArgs e) {  // check error, check cancel, then use result  if (e.Error != null)  {     // handle the error  }  else if (e.Cancelled)  {     // handle cancellation  }  else  {     double result = (double) e.Result;      // use it on the UI thread  }  // general cleanup pre, runs when there was an error or not.}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5567504.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存