You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to cocoa-sharp-dev
Hi Everyone,
I have been having problems when exiting mono applications by right-
clicking the dock icon and selecting 'quit'. I have been able to
isolate the problem to the combination of Cocoa.Application.Run and
using a Mutex. Below you can find the most trivial example I could
come up with.
When starting the application, a mutex is created to ensure this is
the first instance of the application. If it is the first instance, I
execute Cocoa.Application.Init() and Run(). After starting the
application, I open the dock menu and click 'Quit'. Now the
application hangs.
The "run ended", "Exception" and "finally" statements are never
reached.
Could anybody advise me on the steps to take to troubleshoot this
issue? I have tried --trace, but that gives an output of hundreds of
megabytes, so that it is rather unusable I find.
Best Regards,
Erik Renes
// --- EXAMPLE PROBLEMATIC CODE:
using System.Threading;
using System;
using Cocoa;
public class hello{
public static void Main(string[] args){
Mutex mtxMain = null;
try
{
bool bFirstInstance;
mtxMain = new Mutex(true, "Local\\testmutex", out
bFirstInstance);
// bFirstInstance = true; // This is to test what happens
without mutex
if (bFirstInstance)
{
Cocoa.Application.Init();
Cocoa.Application.Run();
Console.Write("run ended");
}
}
// other exceptions
catch (Exception e)
{
Console.WriteLine("Exception: ");
Console.WriteLine(e.ToString());
}
finally{
Console.Write("finally!");
}
}
}
// --- END EXAMPLE CODE
Erik Renes
unread,
Jan 16, 2008, 11:45:51 AM1/16/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to cocoa-sharp-dev
Hi all,
I have read a bit of documentation, and I have solved the problem by
changing the approach I took for cleanup.
I have found that control is never given back to the 'main' function
after terminating, so I created an event handler as suggested in the
documentation. Cocoa# syntax as reference to others:
[Export("applicationWillTerminate:")]
public void ApplicationWillTerminate(Cocoa.Notification not)
{
// Cleanup code here
}
It's rather different from the standard windows forms way of going
about, so it may be worth mentioning somewhere :)