【C#】BackgroundWorker类传递参数
要传递多个不同类型的参数:
private void Test(){
int a = 123;
string b = "456";
bool c = true;
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += (o, ea) =>
{
Worker_DoWork<T>(a, b, c); // 可以使用泛型
};
worker.RunWorkerCompleted += (o, ea) =>
{
// 完成后的回调
};
worker.RunWorkerAsync();
}
private void Worker_DoWork<T>(int a, string b, bool c)
{
// 执行操作
}