0
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);
        }
    }

オプションのパラメーターを new Action() に指定する方法がわかりません。

新しい Action(UpdateDataGrid) を試しましたが、まだランタイム エラーがスローされます。

ありがとう

4

1 に答える 1

6

メソッドの呼び出しをカプセル化するメソッド デリゲートを作成し、最初に指定された引数を次のように渡す必要があります。

() => 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);
    }
}    
于 2012-05-25T21:43:41.123 に答える