Reputation: 107
There is a legacy project. There are a lof of Asynchronous delegates and code like this:
IAsyncResult result = startDelegate.BeginInvoke(param1,
param2,
new AsyncCallback(CallbackMethod),
null);
or just completely parameterless calls like
IAsyncResult result = startDelegate.BeginInvoke(CallbackMethod,null);
The main purpose of desired refactoring is: performance. Many places in the project has been optimized a lot and now it's time for async stuff. From performance point of view: is there any sense to migrate from Async delegates calls to:
so, general question: how bad (or not bad) from performance point of view Async delegates in compare with 1)-3) above?
Upvotes: 1
Views: 102
Reputation: 457217
The main purpose of desired refactoring is: performance.
You almost certainly won't see noticeable performance gains from changing this. However, there are two major benefits for replacing Delegate.BeginInvoke
calls:
async
/await
is the style of asynchronous programming that is most maintainable.Delegate.BeginInvoke
, so if you ever move from .NET Desktop Framework to .NET Core, you'll need to change this code. Side note: there are some pretty good performance benefits just from migrating to .NET Core.If you do choose to remove the calls to BeginInvoke
, I recommend using Task.Run
. It's a modern solution.
Upvotes: 3