How to implement a cancel event in C#

后端 未结 5 1471
星月不相逢
星月不相逢 2021-02-12 12:28

I know that in C#, there are several built in events that pass a parameter (\"Cancel\") which if set to true will stop further execution in the object that raised the eve

5条回答
  •  渐次进展
    2021-02-12 13:13

    It's really easy.

    private event _myEvent;
    
    // ...
    
    // Create the event args
    CancelEventArgs args = new CancelEventArgs();
    
    // Fire the event
    _myEvent.DynamicInvoke(new object[] { this, args });
    
    // Check the result when the event handler returns
    if (args.Cancel)
    {
        // ...
    }

提交回复
热议问题