使用反射动态加载一个C#类库编译成的dll,用下面的代码直接调用方法是没问题的。但是如果要用委托异步调用这个WriteString方法或是多线程来运行这个方法,我就不知道该如何写了。网上到处都没找到相关的内容,只有来这里请教大家了。
System.Reflection.Assembly ass;
Type type;
object obj;ass = System.Reflection.Assembly.LoadFile(@"c:\test.dll");
type = ass.GetType("Webtest.ReflectTest")
obj = ass.CreateInstance("Webtest.ReflectTest");System.Reflection.MethodInfo method = type.GetMethod("WriteString");
string s = (string)method.Invoke(obj, new string[] { "hello" }); 
textBox1.Text += (s + "\r\n");
下面是我平时使用的异步调用代码,红色的部分用来指定方法名。反射得到的方法在这里就不知道如何处理了。delegate List<string> FuncHandle();
FuncHandle _fh = new FuncHandle(ReflectTest.WriteString);
var callback = new AsyncCallback(WorkStoped);
_fh.BeginInvoke(callback, null);)