我有一个处理OnQuit另一个正在运行的应用程序事件的应用程序。OnQuit处理上述事件后,如何引发其他(自定义)事件。
我的OnQuit管理员:
private void StkQuit()
{
_stkApplicationUi.OnQuit -= StkQuit;
Marshal.FinalReleaseComObject(_stkApplicationUi);
Application.Exit();
}
Run Code Online (Sandbox Code Playgroud)
我通常会在我的视图界面中有一个事件,如下所示:
public interface ITestView
{
event EventHandler OnSomeEvent;
}
Run Code Online (Sandbox Code Playgroud)
然后,我将通过演示者构造函数连接这些事件:
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
}
}
Run Code Online (Sandbox Code Playgroud)
从你的 aspx 代码隐藏中:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
希望有帮助!
| 归档时间: |
|
| 查看次数: |
2161 次 |
| 最近记录: |