How about something like this:
public void GetDocumentWithCallback(Action<MyClass> callback, long ID)
{
Task<MyClass> task = GetDocumentAsync(ID);
task.ContinueWith(t => callback(t.Result));
}
NB: Unlike the
async
version,
callback
will not be executed in the same context as the caller. That means you won't be able to access the UI in a Windows Forms / WPF application, and
HttpContext.Current
will not be set in an ASP.NET application.
If that's a problem, you'll have to explicitly capture and restore the context:
public void GetDocumentWithCallback(Action<MyClass> callback, long ID)
{
Task<MyClass> task = GetDocumentAsync(ID);
ExecutionContext context = ExecutionContext.Capture();
ContextCallback contextCallback = state => callback((MyClass)state);
task.ContinueWith(t => ExecutionContext.Run(context, contextCallback, t.Result));
}