我有一个Windows移动应用程序,需要继续运行才能在后台执行某项任务。
要隐藏应用而不是关闭它很容易:
protected override void OnClosing(CancelEventArgs e)
{
e.Cancel = true;
this.Hide();
base.OnClosing(e);
}
问题:当用户在菜单中启动时,如何再次显示应用程序?
Windows Mobile确实知道应用程序仍在运行,因此它不会启动第二个副本。相反,它什么也没做。
如果应用程序再次启动,是否有任何方法可以获得通知,因此应用程序可以显示它的gui?
答案 0 :(得分:3)
你应该用这个:
protected override void OnClosing(CancelEventArgs e) {
if ( false == this.CanClose ) { // you should check, if form can be closed - in some cases you want the close application, right ;)?
e.Cancel = true; // for event listeners know, the close is canceled
}
base.OnClosing(e);
if ( false == this.CanClose ) {
e.Cancel = true; // if some event listener change the "Cancel" property
this.Minimize();
}
}
“Minimize”方法应该在此博客文章中显示(http://christian-helle.blogspot.com/2007/06/programmatically-minimize-application.html)。