I don't have an answer for you exactly, and a comment wouldn't hold my code sample; but I can tell you that I'm conceptually doing almost exactly the same thing in my application and it works just fine. My code:
private static void OnException(Exception ex)
{
new NSObject().InvokeOnMainThread(() => {
try
{
using (ErrorWindowController frmErrorMessage = new ErrorWindowController(ex))
{
Console.WriteLine(ex);
NSApplication.SharedApplication.RunModalForWindow(frmErrorMessage.Window);
}
}
finally
{
NSApplication.SharedApplication.Terminate(NSApplication.SharedApplication);
}
});
}
EDIT:
Make sure you are stopping the modal session when you close the window, or the call to RunModalForWindow
will never return.
I close my modal window using a button, something like this:
partial void butClose_Click(NSObject sender)
{
this.Window.OrderOut(sender);
this.Window.Close();
NSApplication.SharedApplication.StopModal();
}