I have an application that handles the OnQuit
event of another running application. How can I raise an additional (custom) event when said OnQuit
event is handled.
My OnQuit
handler:
private void StkQuit()
{
_stkApplicationUi.OnQuit -= StkQuit;
Marshal.FinalReleaseComObject(_stkApplicationUi);
Application.Exit();
}
I will usually have an event in my view interface like so:
public interface ITestView
{
event EventHandler OnSomeEvent;
}
Then from a presenter constructor I'll wire up those events:
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
}
}
And from your 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();
}
}
Hope that helps!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With