i have a need to invoke some methods asynchrounously. On startup, the app does some work on initializing a few things but I don't want the UI to be held up. So, this function is performed in a separate thread using Threadpool queueitem method.
I was thinking to have a few methods similar to below.
protected void Page_Load(object sender, EventArgs e)
{
DoAsyncOperation(new Func<string, int>(TestMethod), "test");
}
private int TestMethod(string p)
{
return 0;
}
public bool DoAsyncOperation(Delegate asyncMethod, params object[] args)
{
return ThreadPool.QueueUserWorkItem( delegate {asyncMethod.DynamicInvoke(args);});
}
so that in future other methods can also be run async if needed and its all in one place. If I have to change logic for the threading, I can do it in a single method.
Is there any performance issues with this approach, passing in the method dynamically?