In response to your first question (if I understood correctly), the answer is yes: I think you are looking for the AsyncOperation
class, which can handle reporting progress and completed events back to the calling thread using its Post
and PostOperationCompleted
methods. This is what the BackgroundWorker
is doing under the hood.
See: AsyncOperation Class
private AsyncOperation asyncOperation;
public void DoSomethingAsync()
{
this.asyncOperation = AsyncOperationManager.CreateOperation(null);
ThreadPool.QueueUserWorkItem(s => this.DoSomethingImpl());
}
private void DoSomethingImpl()
{
// report progress
this.asyncOperation.Post(new SendOrPostCallback(...), null);
// report complete
this.asyncOperation.PostOperationCompleted(new SendOrPostCallback(...), null);
}