首页 > 代码库 > BackgroundWorker之启动任务

BackgroundWorker之启动任务

public static void RunBackgroundTask<T>(Func<T> argBackgroundFunc,Action<T> argCompletedAction){    BackgroundWorker worker = new BackgroundWorker();    worker.DoWork += (sender,e) => e.Result = argBackgroundFunc();    if(argCompletedAction != null)    {        worker.RunWorkerCompleted += (sender,e) => argCompletedAction((T)e.Result);    }    worker.RunWorkerAsync();}

 调用:

 1 BackgroundTask.RunBackgroundTask<List<PevcOrg>>(()=> 2 { 3     return pevcService.GetAll().FindAll(x=>x.Name.Contains(fundName)); 4 }, 5 ltOrg => 6 { 7     if(ltOrg != null) 8     { 9     SetDataGridSource(ltOrg);10     }11 });

 

  

BackgroundWorker之启动任务