匹配代理' System.Action'没有重载 [英] No overload for matches delegate 'System.Action'

查看:137
本文介绍了匹配代理' System.Action'没有重载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public void UpdateDataGrid(bool newInsert = false)
    {

        //ThreadSafe (updating datagridview from AddEventForm is not allowed otherwise 
        if (InvokeRequired)
        {
            Invoke(new Action(UpdateDataGrid));
        }
        else
        {
            Util.PopulateDataGridView(ref this.EventsDataGridView,newInsert);
        }
    }

我不知道如何为新的Action()提供可选参数.

I don't know how to provide the optional parameter to new Action().

我尝试了新的Action(UpdateDataGrid),但仍然抛出运行时错误.

I tried new Action(UpdateDataGrid) but still throws a runtime error.

谢谢

推荐答案

您需要创建一个方法委托,封装方法的调用,并传递最初指定的参数,例如:

You need to create a method delegate encapsulating the invocation of your method, passing the argument originally specified, like so:

() => UpdateDataGrid(newInsert)

在上下文中:

public void UpdateDataGrid(bool newInsert = false)
{

    //ThreadSafe (updating datagridview from AddEventForm is not allowed otherwise 
    if (InvokeRequired)
    {
        Invoke(new Action(() => UpdateDataGrid(newInsert)));
    }
    else
    {
        Util.PopulateDataGridView(ref this.EventsDataGridView,newInsert);
    }
}    

这篇关于匹配代理' System.Action'没有重载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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