我正在尝试使用调度程序更新进度条,但不知何故无法想到在哪里放置调度程序。调用以及在其中传递什么内容。
我正在尝试导入文件,并且需要使用进度栏向用户显示导入了多少文件。
所以我有一个代表:
public delegate void DelegateA(ProgressClass progressClass);
我调用委托并传递要调用的函数。
DelegateA(FunctionA);
因此,在导入每个文件时,它会调用该函数。
private void FunctionA(ProgressClass progressClass)
{
**//Put dispatcher.invoke here?**
progressbar.updateprogress(progressclass);
progressbar.show();
}
Progress类有两个属性,用于设置进度条的值(已处理的数量)和要处理的总项目数。
我无法理解 InvokeMethod(THreadPriority, delegate method) 中传递什么委托方法?
抱歉,如果有不清楚的地方。
如果您尝试从某些非 UI 线程更新 UI,您可以执行以下操作。
//here progress bar is a UIElement
progressBar.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Normal
, new DispatcherOperationCallback(delegate
{
progressBar1.Value = progressBar1.Value + 1;
//do what you need to do on UI Thread
return null;
}), null);
这段代码取自一个好的post关于从后台线程更新 UI
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)