C# 如何在引发另一个事件时引发该事件?

C# 如何在引发另一个事件时引发该事件?,c#,events,C#,Events,我有一个处理另一个正在运行的应用程序的OnQuit事件的应用程序。当处理了上述OnQuit事件时,如何引发其他(自定义)事件 我的OnQuit处理程序: private void StkQuit() { _stkApplicationUi.OnQuit -= StkQuit; Marshal.FinalReleaseComObject(_stkApplicationUi); Application.Exit(); } 在OnQuit注册后,只需向_stkaApplicatio

我有一个处理另一个正在运行的应用程序的
OnQuit
事件的应用程序。当处理了上述
OnQuit
事件时,如何引发其他(自定义)事件

我的
OnQuit
处理程序:

private void StkQuit()
{
   _stkApplicationUi.OnQuit -= StkQuit;
   Marshal.FinalReleaseComObject(_stkApplicationUi);
   Application.Exit();
}

在OnQuit注册后,只需向_stkaApplication注册此附加事件

_stkApplicationUi.OnQuit += StkQuit;
_stkApplicationUi.OnQuitAdditional += AddlQuitHandler;

其中AddlQuitHandler是自定义事件的处理程序,我的视图界面中通常会有这样一个事件:

public interface ITestView
    {
        event EventHandler OnSomeEvent;
    }
然后,我将从presenter构造函数连接这些事件:

public class TestPresenter : Presenter
{
    ITestView _view;

    public TestPresenter(ITestView view)
    {
        _view.OnSomeEvent += new EventHandler(_view_OnSomeEvent);
    }

    void _view_OnSomeEvent(object sender, EventArgs e)
    {
        //code that will run when your StkQuit method is executed
    }
}
从您的aspx codebehind:

public partial class Test: ITestView
{
     public event EventHandler OnSomeEvent;
     public event EventHandler OnAnotherEvent;

    private void StkQuit()
    {
        _stkApplicationUi.OnQuit -= StkQuit;
        Marshal.FinalReleaseComObject(_stkApplicationUi);
        if (this.OnSomeEvent != null)
        {
            this.OnSomeEvent(this, EventArgs.Empty);
        }
        Application.Exit();
    }
}

希望有帮助

与创建任何其他事件的方式相同。