Hi,
I am making an windows service similar to windows task schedular. The service would invoke the methods of some assemblies at some predefined schedules. (windows service read the method/assembly and schedule info from app.config file)
I am using reflection to dynamically load the assemblies and then want to call a method of that assembly on separate thread. I am using code similar to following :
public void InvokeMethodOfAnotherAssembly()
{
string AssemblyName = @"D:\SchedularService\TesterApplication\bin\Debug\ TesterApplication.dll";
string ClassName = "TesterClass";
string MethodName = "TesterMethod";
Assembly AnotherAssembly
Type AssemblyType;
MethodInfo MethodInfo;
Thread thread;
ThreadStart threadDelegate;
AnotherAssembly = Assembly.LoadFrom(AssemblyName);
AssemblyType = AnotherAssembly.GetType(AnotherAssembly.GetName(). Name + "." + ClassName, true, true);
MethodInfo = AssemblyType.GetMethod(MethodName);
threadDelegate = (ThreadStart)ThreadStart.CreateDelegate(AssemblyTy pe, MethodInfo);
thread = new Thread(threadDelegate);
thread.Start();
}
When i run the above code I get following exception:
"An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: Type must derive from Delegate."
I can't understand why exception is occuring. Can anyone give me a clue or a workaround for the scenario.
Thanks,
Ajay