代表问题 [英] Problem in delegate

查看:88
本文介绍了代表问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,
我想像这种方式使委托遵循这种方法,但是它不起作用.

Dear,
I want to make delegate following this method like this way but it won''t work.

private delegate void CopyFileDelegate(string srcDir, string DesDir);

public void CopyFile(string srcDir, string DesDir)
{
    if (txtLoadPath.InvokeRequired == false)
    {
    }
    else
    {
        txtLoadPath.BeginInvoke(new CopyFileDelegate(CopyFile(srcDir, DesDir)), new object[] {});  // Here is the problem
    }
}


错误说需要的方法.
这里有什么问题,我该怎么办.请帮我.我是新来的代表.
Mahmud


error said method needed.
what''s wrong here, what should I do. Please help me. I am new in delegate.
Mahmud

推荐答案

在创建委托的实例时,您无需指定参数.有关某些示例,请此处您正在尝试做的事情.
You don''t specify parameters when creating an instance of a delegate. Look here for some examples of what you are trying to do.


您可以尝试--
You could try this -
CopyFileDelegate objD = new CopyFileDelegate(CopyFile);
txtLoadPath.BeginInvoke(objD, new object[] { srcDir , DesDir});


您的txtLoadPath.BeginInvoke接受CopyFileDelegate类型的委托作为第一个参数.您错误地创建了此委托的实例.
代替:

Your txtLoadPath.BeginInvoke accepts a delegate of CopyFileDelegate type as the first parameter. You create an instance of this delegate incorrectly.
Instead of:

<br />
new CopyFileDelegate(CopyFile(srcDir,DesDir))



请写:



please write:

<br />
new CopyFileDelegate(CopyFile)



您的代码应为:



Your code should be:

private delegate void CopyFileDelegate(string srcDir,string DesDir);
       public void CopyFile(string srcDir,string DesDir)
       {
           if (txtLoadPath.InvokeRequired == false)
           {
           }
           else
            {
        txtLoadPath.BeginInvoke(new CopyFileDelegate(CopyFile), new object[] {});
            }
       }


这篇关于代表问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆