2

To do cross-thread operations, I use the following:
this.Invoke(new MethodInvoker(() => myMethod());

However, I can't do, for example, the following:

this.Invoke(new MethodInvoker(() => bool myBool = getBool()); 
return myBool;

How would I do this? I can't just do bool myBool = getBool();
because I get a cross-threading operation error.

Thanks in advance.

4

2 回答 2

4

尝试这个:

delegate T MyDelegate<out T>();
public bool MethodName()
{
    bool b = (bool)this.Invoke(new MyDelegate<bool>(() => getBool()));
    return b;
}
于 2013-07-28T10:00:20.720 回答
1

不明白你的意思

但你可以做这样的事情

bool myBool = false;
this.Invoke(new MethodInvoker(() => myBool = getBool()));
return myBool;

如果我错了,请让我清楚

于 2013-07-28T09:54:51.190 回答