6

I'm trying to shutdown a MonoMac application by using Environment.Exit(0). However, this call for some reason does not return. It does not throw an exception, either. When I execute the function in the immediate window in MonoDevelop, it times out.

I have no idea how to approach debugging this. I thought that Environment.Exit kills the process...

sohum
  • 3,207
  • 2
  • 39
  • 63

2 Answers2

6

You should use the NSApplication.Terminate method instead.

Note that this method may call the application delegate (if defined) to confirm the termination (See NSApplicationDelegate.ApplicationShouldTerminate).

Laurent Etiemble
  • 27,111
  • 5
  • 56
  • 81
  • 3
    Sweet, that worked perfectly. I called `NSApplication.SharedApplication.Terminate(this)` in my controller. – sohum Oct 21 '11 at 14:43
3

You may add two override functions in AppDelegate.cs.

public override NSApplicationTerminateReply ApplitionShouldTerminate(NSApplication sender) 
{
    mainWindowController.Window.Close();
    return NSApplicationTerminateReply.Now;
}

public override bool ApplicationShouldTerminateAfterLastWindowClosed(NSApplication sender)
{
    return true;
}
Utmost
  • 51
  • 1