C# Is action.BeginInvoke(action.EndInvoke,null) a good idea?

前端 未结 2 1469
说谎
说谎 2021-02-13 15:31

If I want to do a \"fire and forget\" of some code, but still want to ensure that my memory is cleaned up (per Why does asynchronous delegate method require calling EndInvoke?),

2条回答
  •  日久生厌
    2021-02-13 15:53

    Nowdays it could be done like

    BeginInvoke((Action)(async () =>
    {
        // Show child form
        var f = new MyForm();
        f.ShowDialog();
        // Update parent/current
        await UpdateData();
    }));
    

提交回复
热议问题