C# 调用isn';我不在上课
我有一个类,我使用委托并调用此列表:C# 调用isn';我不在上课,c#,windows,forms,invoke,C#,Windows,Forms,Invoke,我有一个类,我使用委托并调用此列表: delegate void delSetMsg(string message, bool burlar); public void setMsg(string message, bool burlar) { if (this.InvokeRequired) { this.BeginInvoke(new delSetMsg(setMsg), message, burlar); } else {
delegate void delSetMsg(string message, bool burlar);
public void setMsg(string message, bool burlar)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new delSetMsg(setMsg), message, burlar);
}
else
{
if (burlar == true || canWrite() == true)
{
frm_server frm_server = new frm_server();
frm_server.rtbox_servermsg.Text += message + "\n";
}
}
}
程序向我显示这个错误CS1061,到“invokererequired”和“BeginInvoke”。我正在使用这个使用s:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;
错误CS1061表示:“'serverclass'不包含'BeginInvoke'的定义,并且找不到接受第一个'serverclass'类型参数的扩展方法'BeginInvoke'(是否缺少using指令或程序集引用?)”。serverclass是我的类的名称。您的类不是从控件继承的,因此没有理由对其调用调用。据我所知,您不需要在新表单上调用。但问题是我需要做这个条件测试,这是一种在类上调用控件的方法?我的观点是,您不需要做那个检查。invokererequired
和Invoke
的要点是,代码在特定UI控件的正确线程上运行。在本例中,不存在有问题的控件,因此任何线程都可以。再一次,据我所知,你根本不需要那张支票。如果有任何问题,检查将在frm\u服务器上进行。invokererequired
,但我几乎可以肯定的是,您在新表单上的正确上下文不会有任何问题。哦,thx,我会处理这个问题,如果您想将此注释作为答案发布,我会检查它。您的类不会从控件继承,所以没有理由对它调用Invoke
。据我所知,您不需要在新表单上调用。但问题是我需要做这个条件测试,这是一种在类上调用控件的方法?我的观点是,您不需要做那个检查。invokererequired
和Invoke
的要点是,代码在特定UI控件的正确线程上运行。在本例中,不存在有问题的控件,因此任何线程都可以。再一次,据我所知,你根本不需要那张支票。如果有任何问题,检查将在frm_服务器上进行。invokererequired
,但我几乎可以肯定的是,您在新表单上的正确上下文不会有任何问题。哦,thx,我会处理这个问题,如果您想将此评论作为答案发布,我会检查它。