I have a method that queues some jobs that are executed asynchronously. I would like to return some descriptor to the caller, which can be interrogated, wait, or used to get the return value from the operation, but I can not find a class or interface suitable for the task.
BackgroundWorker is approaching, but it focuses on the case when the employee has his own dedicated thread, which is wrong in my case. IAsyncResult looks promising, but the provided AsyncResult implementation is also unsuitable for me. Should I implement IAsyncResult myself?
Explanation
I have a class that conceptually looks like this:
class AsyncScheduler
{
private List<object> _workList = new List<object>();
private bool _finished = false;
public SomeHandle QueueAsyncWork(object workObject)
{
_workList.Add(workObject);
return SomeHandle;
}
private void WorkThread()
{
while (!_finished)
{
foreach (object workObject in _workList)
{
if (!workObject.IsFinished)
{
workObject.DoSomeWork();
}
}
Thread.Sleep(1000);
}
}
}
QueueAsyncWork , . QueueAsyncWork - . , ? SomeHandle?
.Net , , . - , workObject.DoSomeWork(). , - , ?