使用反射动态加载一个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);)
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);)
解决方案 »
- MDI中打开一个子窗口
- C#MD5算法
- 页面提交出错,返回后如何保存原来填写的信息?
- C#中如何让某一个TabControl控件的tabPage暗(暂时不能使用)
- c# dataGridView 光标选中文字,点别的按钮,如何让选中文字不变,而不是自动选中整行
- 瑛勴(CLOUD)来接分。谢谢你的程序。
- DirectX9 的April 2005 Update版本不包含DirectShow?
- 自己编一控件,要求标题栏在最上面,并有上下左右滚动条,能做到吗?
- 请问,那个博酷网的网址是什么?
- 请各位高手指点一下有什么c#的web编程的经典书籍??
- System.Web.HttpUtility.HtmlDecode(location)无效?
- 如何控制各个控件之间的间距?
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");
new Thread((ThreadStart)delegate
{
string s = (string)method.Invoke(obj, new string[] { "hello" });
textBox1.Invoke((EventHandler)delegate{textBox1.Text += (s + "\r\n");});
}).Start();