Use*_*r.1 5 c# multithreading winforms
为了尝试对线程进行精心掌握,我尝试了猴子看猴子,并在MSDN上的THIS_PAGE中复制(如读取和输入,而不是剪切和粘贴).
当我这样做时,我得到以下错误
错误2找不到类型或命名空间名称'SetTextCallback'(您是否缺少using指令或程序集引用?)Form1.cs 385 17 ZYX987
错误3找不到类型或命名空间名称'SetTextCallback'(您是否缺少using指令或程序集引用?)Form1.cs 385 41 ZYX987
我在网页上向下滚动,发现很多社区评论表明每个人都有完全相同的问题,因为这个例子具有误导性.即,SetTextCallback
永远不会被宣布.
这是我在盯着MSDN页面时输入的模仿版本......
private void SetText(string text)
{
// InvokeRequired required compares the thread ID of
// the calling thread to the thread ID of the
// creating thread. If these threads are different,
// it returns true
if (this.label1.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.label1.Text = text;
}
}
Run Code Online (Sandbox Code Playgroud)
请问有人SetTextCallback
在我的CopyCatCode中建议我应该放在哪里吗?
第二个问题:声明它的语法是什么样的?
第三个问题:如果SetTextCallback
是一种方法,那么它应该是什么?
我在Stack Overflow上搜索了"... SetTextCallback ..."(没有引号)并找到了一些引用,但不是这个确切的问题.希望这是属于这里的问题.谢谢阅读.
sin*_*law 10
在链接到的msdn页面中向下滚动(" 如何:对Windows窗体控件进行线程安全调用 "),完整源代码列在底部.你会在那里找到定义:
// This delegate enables asynchronous calls for setting
// the text property on a TextBox control.
delegate void SetTextCallback(string text);
Run Code Online (Sandbox Code Playgroud)