My suggestion...

Feb 22, 2010 at 4:20 PM

You don't need to use VB objects: http://blogs.microsoft.co.il/blogs/maxim/archive/2010/02/13/single-instance-application-manager.aspx

Coordinator
Feb 22, 2010 at 5:40 PM

This solution doesn't use VB objects at all, could you point out which part, in your opinion, uses VB objects?

This solution uses remoting and Mutexes/EventWaitHandle to synchronize multiple instances, and does not even reference the VB-specific assembly.

 

I had a look at your solution, notice that the function

 

private static void RegisterRemoteType(string uri)

 

will throw an exception if multiple instances are running on different sessions, causing a second application to crash, instead of closing cleanly, trying to create the IpcChannelServer, while it already exists.

I have some complaints about the fact that there is too few code to synchronize the instances and avoid race conditions, and a bit of carelessness about handling a ThreadAbortException.

I still think that this solution is cleaner, at least in a WPF environment.

Please, feel free to report every issue you can spot with the proposed implementation.