其中C#程序集包含调用? [英] Which C# assembly contains Invoke?

查看:140
本文介绍了其中C#程序集包含调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

备用的问题:为什么是VS10如此热衷抱怨调用

Alternate question: Why is VS10 so keen to complain about Invoke?

在我不断的追求? <击>让我的应用程序的工作成为世界上最好的C#程序员,我已经决定,线程是一个好东西™。

In my continuing quest to make my app work become the worlds best C# programmer, I have decided that threads are a Good Thing™.

MSDN有一个有用的文章使得线程安全的呼叫控制的,但它(貌似所有其他文章主体)倾斜引用了一个名为Invoke方法。有时甚至BeginInvoke的,这我读过是首选

MSDN has a helpful article on making thread-safe calls to controls, but it (and seemingly every other article on the subject) obliquely references a method called Invoke. Sometimes even BeginInvoke, which I've read is to be preferred.

这一切都将是巨大的,如果我能得到视觉工作室识别调用。 MSDN说它被包含在System.Windows.Forms的组件时,但我已经'使用'的。可以肯定的,我也尝试过使用的System.Threading,但无济于事。

All this would be great, if I could get visual studio to recognise Invoke. MSDN says that it is contained in the System.Windows.Forms assembly, but I'm already 'using' that. To be sure, I've also tried using System.Threading, but to no avail.

箍做我需要跳通过让调用工作?

What hoops do I need to jump through to get invoke working?

推荐答案

调用是控制之内。即 Control.Invoke();

有没有办法来调用直接调用,因为在<$ C这样的方法$ C> System.Windows.Forms的。 invoke方法是控制部件。

There's no way to call Invoke directly as there's no such method in System.Windows.Forms. The Invoke method is a Control Member.

下面是一个的例如我早些时候所作:

Here's an example I made earlier:

public delegate void AddListViewItemCallBack(ListView control, ListViewItem item);
public static void AddListViewItem(ListView control, ListViewItem item)
{
    if (control.InvokeRequired)
    {
        AddListViewItemCallBack d = new AddListViewItemCallBack(AddListViewItem);
        control.Invoke(d, new object[] { control, item });
    }
    else
    {
        control.Items.Add(item);
    }
}

这篇关于其中C#程序集包含调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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