E
eusebiu
Hello....
On the main thread of an application I create a number(20) of
BackgroundWorkers that have on their DoWork event a method that
creates an Assembly using this class :
public class InvokeDynamicMethod
{
public void InvokeMethod(string assemblyName, string
className, string methodName, out object result, params object[]
arguments)
{
Assembly assembly = Assembly.LoadFrom(assemblyName);
// Walk through each type in the assembly
foreach (Type type in assembly.GetTypes())
{
// Pick up a class
if (type.IsClass == true && type.Name == className)
{
// create an instance of the object
object ibaseObject =
Activator.CreateInstance(type);
// Dynamically Invoke the
Method
result = type.InvokeMember(methodName,
BindingFlags.Default | BindingFlags.InvokeMethod,
null, ibaseObject,
arguments);
return;
}
}
result = null;
}
}
The method that takes care of the DoWork event is :
void Form1_DoWork(object sender, DoWorkEventArgs e)
{
object result;
InvokeDynamicMethod met = new InvokeDynamicMethod();
met.InvokeMethod(Assembly.GetAssembly(this.GetType()).Location,
"Form1", "DoMyWork", out result,
3, sender);
}
and DoMyWork is a method inside the Form1 class.
public void DoMyWork(params object[] pars)
{
//do some work here...in the new generated assembly
}
The problem is that I want to block the calling thread in my
dynamically generated method(the BackgroundWorker that creates the
assembly) and from the main thread(the application thread) to signal
all my BackgroundWorkers to continue their work.
Can someone help me with this?
Thanks
On the main thread of an application I create a number(20) of
BackgroundWorkers that have on their DoWork event a method that
creates an Assembly using this class :
public class InvokeDynamicMethod
{
public void InvokeMethod(string assemblyName, string
className, string methodName, out object result, params object[]
arguments)
{
Assembly assembly = Assembly.LoadFrom(assemblyName);
// Walk through each type in the assembly
foreach (Type type in assembly.GetTypes())
{
// Pick up a class
if (type.IsClass == true && type.Name == className)
{
// create an instance of the object
object ibaseObject =
Activator.CreateInstance(type);
// Dynamically Invoke the
Method
result = type.InvokeMember(methodName,
BindingFlags.Default | BindingFlags.InvokeMethod,
null, ibaseObject,
arguments);
return;
}
}
result = null;
}
}
The method that takes care of the DoWork event is :
void Form1_DoWork(object sender, DoWorkEventArgs e)
{
object result;
InvokeDynamicMethod met = new InvokeDynamicMethod();
met.InvokeMethod(Assembly.GetAssembly(this.GetType()).Location,
"Form1", "DoMyWork", out result,
3, sender);
}
and DoMyWork is a method inside the Form1 class.
public void DoMyWork(params object[] pars)
{
//do some work here...in the new generated assembly
}
The problem is that I want to block the calling thread in my
dynamically generated method(the BackgroundWorker that creates the
assembly) and from the main thread(the application thread) to signal
all my BackgroundWorkers to continue their work.
Can someone help me with this?
Thanks