I would like to know if there is any overhead incurred through the use of anonymous methods when creating a Background worker.
for example:
public void S
This is what decompiler said:
[CompilerGenerated]
private static DoWorkEventHandler CS$<>9__CachedAnonymousMethodDelegate1;
[CompilerGenerated]
private static void b__0(object sender, DoWorkEventArgs e)
{
throw new NotImplementedException();
}
public void SomeMethod1()
{
BackgroundWorker worker = new BackgroundWorker();
BackgroundWorker backgroundWorker = worker;
backgroundWorker.DoWork += (object sender, DoWorkEventArgs e) => throw new NotImplementedException();
worker.RunWorkerAsync();
}
public void SomeMethod2()
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += worker_DoWork;
worker.RunWorkerAsync();
}
private void worker_DoWork(object sender, DoWorkEventArgs e)
{
throw new NotImplementedException();
}
Edit:
Looking at IL code there is only small overhead in creating/assigning method to delegate for the first time.