worker-process

How to make BackgroundWorker return an object

六眼飞鱼酱① 提交于 2019-11-27 06:47:45
I need to make RunWorkerAsync() return a List<FileInfo> . How can I return an object from a background worker? In your DoWork event handler for the BackgroundWorker (which is where the background work takes place) there is an argument DoWorkEventArgs . This object has a public property object Result. When your worker has generated its result (in your case, a List<FileInfo> ), set e.Result to that, and return. Now that your BackgroundWorker has completed its task, it triggers the RunWorkerCompleted event, which has a RunWorkerCompletedEventArgs object as an argument. RunWorkerCompletedEventArgs

How to make BackgroundWorker return an object

孤者浪人 提交于 2019-11-26 12:10:00
问题 I need to make RunWorkerAsync() return a List<FileInfo> . How can I return an object from a background worker? 回答1: In your DoWork event handler for the BackgroundWorker (which is where the background work takes place) there is an argument DoWorkEventArgs . This object has a public property object Result. When your worker has generated its result (in your case, a List<FileInfo> ), set e.Result to that, and return. Now that your BackgroundWorker has completed its task, it triggers the