Sam
Sam

Reputation: 29009

Hide windows mobile app instead of closing

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?

Upvotes: 2

Views: 1565

Answers (1)

TcKs
TcKs

Reputation: 26632

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 ).

Upvotes: 3

Related Questions