C# – Hide windows mobile app instead of closing

chidewindows-mobile

I've got a windows mobile app, which needs to keep running to do some task in the background.

To hide the app instead of closing it was easy:

protected override void OnClosing(CancelEventArgs e)
{
  e.Cancel = true;
  this.Hide();
  base.OnClosing(e);
}

The problem: how do I show the app again, when the user starts it in the menu?
Windows Mobile does know the app is still running, so it does not start a second copy. Instead it just does nothing.

Is there any way for the app to get notified if it is started again, so the app can show it's gui?

Best Answer

You should use this:

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();
  }
}

The "Minimize" method should looks like in this blog post ( http://christian-helle.blogspot.com/2007/06/programmatically-minimize-application.html ).

Related Topic