How do I handle data returned from a worker thread public method?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If the worker thread is a
Task<TResult>, then you can retrieve the result from theTask<TResult>.Resultproperty.If the worker thread is a
BackgroundWorker, then you can retrieve the result from theproperty in the argument object passed toRunWorkerCompletedEventArgs.Result
BackgroundWorker.RunWorkerCompleted.If the worker thread is a
ThreadPoolthread executed viaDelegate.BeginInvoke, then you can retrieve the result by callingEndInvoke, even if the delegate has already completed.If the worker thread is a
Thread, or aThreadPoolthread executed viaThreadPool.QueueUserWorkItem, then you must “return” the result by setting a subobject of a parameter, by using a lambda-bound variable, or by using a global variable.