Control.Invoke with input Parameters

后端 未结 8 589
时光说笑
时光说笑 2020-12-08 05:24

From what I\'ve found in C#, the Control.Invoke method requires that you use a delegate with no input parameters. Is there any way around this? I would like to invoke a me

8条回答
  •  离开以前
    2020-12-08 06:05

    Found an elegant method for .net 2.0 with anonymous methods wrapped in a MethodInvoker Delegate. That way is no need to define own delegates all the time. Example:

        private void InitUI(Guid id, string typename)
        {
            MethodInvoker inv = delegate{tvMatrix.Nodes[0].Nodes.Add(id.ToString(), typename);};
            tvMatrix.Invoke(inv);
        }
    

提交回复
热议问题