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 });
时间: 2024-10-10 05:14:59