[英]Action with parameter in Control.BeginInvoke(
Sorry for the noobish question, my syntax is wrong and I cant understand why. 对不起,这个问题很抱歉,我的语法错误,无法理解原因。
internal delegate void DoSomethingWithParam(MyObject localObjectToPassAsParam);
and I use it: 我用它:
myControl.BeginInvoke(new FinishAddingEntitiesToFolderDelegate(FunctionNameWithSignatureAsDelegate), localObjectToPassAsParam);
This will call my function OK: 这将使我的函数正常运行:
private void FunctionNameWithSignatureAsDelegate(MyObject localObjectToPassAsParam)
{
Logger.Debug(localObjectToPassAsParam);
}
This works fine, when I try doing so with anonymous delegate it does not compile. 这很好,当我尝试使用匿名委托进行操作时,它无法编译。
Where Am I suppose to put the parameter ? 我应该将参数放在哪里?
myControl.BeginInvoke((Action<MyObject >)(() =>
{
//I want to use my object here..
}));
Tried it this way? 这样试过了吗?
myControl.BeginInvoke((localObjectToPassAsParam)=>
{
// Your code here
}));
Let localObjectToPassAsParam be the instance of your object ;-) Please try and let me know, whether it worked in terms of type safety. 让localObjectToPassAsParam成为对象的实例;-)请尝试让我知道,它是否在类型安全方面起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.