Change application single instance behaviour
-
Monday, March 16, 2009 8:55 AMIs it possible to change the behaviour that enforces only a single instance of a NETCF 2.0/3.5 application can exist?I've read about the #NETCF_AGL_PARK_filename classname, but as far as i can see there is no way to change the classname of a window.Any ideas/suggestions?Thanks in advance,
Peter Vrenken - MCPD: Enterprise Applications Developer - Sigmax Mobile Solutions
Work: www.sigmaxmobile.com
Home: www.petervrenken.nl
Mobile Development tools: HeadsUp | uTrack | ANit
Mobile technology: xTechnology | TransparaM | Pica.Mo | MoBio
All Replies
-
Monday, March 16, 2009 5:14 PMHi
very easy, just you need work out with mutex.
look here great sample .
http://www.nesser.org/blog/archives/56
thank you
RRave -
Tuesday, March 17, 2009 1:53 PMHello Ravenet,i am searching for a way to allow multiple instances of one single binary, which is by default disabled as of NETCF2.0.Any ideas?Greetings and thanks in advance,
Peter Vrenken - MCPD: Enterprise Applications Developer - Sigmax Mobile Solutions
Work: www.sigmaxmobile.com
Home: www.petervrenken.nl
Mobile Development tools: HeadsUp | uTrack | ANit
Mobile technology: xTechnology | TransparaM | Pica.Mo | MoBio -
Wednesday, March 18, 2009 4:40 AMHi,
Windows Mobile adds no additional behaviour or restrictions to the launching of multiple instances of an application.
Any limits found within a windows mobile application are due to something the application developer has explictly coded or been "provided for free" due to the language / framework they have selected.
Many common frameworks (such as System.Windows.Forms or MFC etc) provide code out of the box to provide this second instance check, but it is the frameworks themself providing it rather than the underlying operating system.
As an example create a new Win32 Smart Device Project (native C/C++). You will notice some code within the InitInstance function that uses FindWindow to find another instance of the main window and exits if it is found. Remove this if statement and you'll allow multiple instances of your application.
The #NETCF_AGL_PARK_ window trick used to work as the .NET CF used both the window class and window title in its search for an existing instance of the application. If you called SetWindowText to alter the window title it was enough to cause the .NET CF to not find it when the second instance launched.
Atleast this is my memory of how things worked previously. Checking it just now it seems that the .NET CF runtime has been modified to look only at the window class (something which is hard to modify) when looking for a second instance. I'll need to investigate further but it appears the old advice of simply changing the window title won't work now.
Hope this helps,
Christopher Fairbairn
Visit my blog at http://www.christec.co.nz/blog/ -
Wednesday, March 18, 2009 8:48 AMHello Christopher,Longe time no see here on the forums. Is all going well on the other side of the world? I happen to notice that there is not that much activity on you're blog.The description you give matches my research. I guess the only way to realise this is to change the window classname of the application before an attempt is made to start it a second time.My findings:
I'm not that of a Win32 guru and do not know of any true voodoo to achieve this. The other approach is by executing a second, copied version of the application, but this does not seem like the correct solution.I've also thought about the why. It isn't common behaviour to execute a application twice, and the best practice is to just create a second application that can be executed. However, in this case keeping the code in one application is prefered because it meant to become part of a reusable diagnostic framework. Distributing, flexibility, configuration and usability is somewhat easier when the developer does not have to worry about another application.If you got a link or something else regarding changing the classname would be great.Greetings,
Peter Vrenken - MCPD: Enterprise Applications Developer - Sigmax Mobile Solutions
Work: www.sigmaxmobile.com
Home: www.petervrenken.nlProfile: www.linkedin.com
Mobile Development tools: HeadsUp | uTrack | ANit
Mobile technology: xTechnology | TransparaM | Pica.Mo | MoBio- Edited by Peter Vrenken Wednesday, March 18, 2009 9:13 PM
-
Wednesday, March 18, 2009 1:01 PM
Hi all,
As you know problem is that NETCF v2.0 does no longer rely on WindowName, which was the undocumented feature Daniel Moth wrote about some years ago (in my blog I usually point to that precise page when I discuss about undocumented features..). Unfortunately afaik it's not possible to modify the ClassName after the window has been created, by using any API (for example SetWindowLong). It's possible to change another property of the window, for example the WindowID (by using SetWindowLong(hWnd, GWL_ID, 12345678), however I couldn't find a function similar to FindWindow that discriminates existing windows with the WindowID criterium.
I would be interested on a solution, even if I think as Peter that the NETCF Dev Team made the choice of not to base the research of the window on WindowName, precisely to avoid that multiple instances for NETCF v2+ application would be running indiscriminately, thus possible eating up the scarce resources of the OS.
In any case very likely you can end up with creative patterns like a shell application that controls running processes and if it finds a live instance of the app then creates a new one with a different name (or something analogous).
Thanks,
~raffaele
http://blogs.msdn.com/raffael
This posting is provided 'as is' with no warranties and confers no rights.

