sooqua sooqua - 2 months ago 14
C# Question

Why should I use AsyncCallback?

I've been using the

Action
as a callback for my async method, and I just stumbled upon
AsyncCallback
.

I am wondering whether should I change the
Action
to
AsyncCallback
? Would there be any difference?

Answer

AsyncCallback is an old delegate that is used when following the Begin / End async pattern with IAsyncResult.

Unless you are using IAsyncResult in your async code, then I wouldn't bother with it.

If you are using something that uses Begin / End, I would suggest using TaskFactory.FromAsync and converting it to an awaitable task.

Comments