我有一个运行长数据库任务的后台工作程序.我想在任务运行时显示进度条.不知何故,后台工作人员不会报告任务的进度.
这就是我所拥有的:
BackgroundWorker _bgwLoadClients;
_bgwLoadClients = new BackgroundWorker();
_bgwLoadClients.WorkerReportsProgress = true;
_bgwLoadClients.DoWork += new DoWorkEventHandler(_bgwLoadClients_DoWork);
_bgwLoadClients.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_bgwLoadClients_RunWorkerCompleted);
_bgwLoadClients.ProgressChanged += new ProgressChangedEventHandler(_bgwLoadClients_ProgressChanged);
_bgwLoadClients.RunWorkerAsync(parms);
private void _bgwLoadClients_DoWork(object sender, DoWorkEventArgs e)
{
DataTable dt = getdate();
e.Result = dt;
}
void _bgwLoadClients_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}
Run Code Online (Sandbox Code Playgroud)
我在WPF中这样做,但我想它不会有所作为.
提前致谢
我已经四处搜索,将枚举绑定到组合框似乎很容易,只需通过静态Enum.GetValues方法通过ObjectDataProvider将Enum值作为字符串列表检索,但是我无法使其工作.错误是未找到类型ContactExportType.
我有一个名为ContactExportType的枚举,它驻留在Enums类中.此类是CEM.Marketing.Objects命名空间的一部分.
这就是我所拥有的:
<UserControl
xmlns:local="clr-namespace:CEM.Marketing.Objects"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Grid>
<Grid.Resources>
<ObjectDataProvider MethodName="GetValues"
ObjectType="{x:Type sys:Enum}"
x:Key="ContactExportTypes">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="local:ContactExportType" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Grid.Resources>
</Grid>
<ComboBox
ItemsSource="{Binding {StaticResource ContactExportTypes}}"
...
Run Code Online (Sandbox Code Playgroud)
谢谢,安吉拉