Your original StartTask
method:
private void StartTask<T>(string, string2, string3) where T : BaseClass10
{
var instance = (T) Activator.CreateInstance(typeof (T), string, string2, string3);
Task.Factory.StartNew(() => instance);
}
If the long running process happens in the constructor of T
, then notice that the long running process happens outside of Task.Factory.StartNew()
.
Move the long running process into a method (e.g LongRunningProcess()
) on T
, then you can do this:
private void StartTask<T>(string, string2, string3) where T : BaseClass10
{
var instance = (T) Activator.CreateInstance(typeof (T), string, string2, string3);
Task.Factory.StartNew(() => instance.LongRunningProcess());
}
I don't think it's a good idea to have the long running process happening in a constructor.