Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / April 2006

Tip: Looking for answers? Try searching our database.

single instance of app

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tim Wallace - 25 Apr 2006 15:16 GMT
I posted this over a week ago and got no response, so here it goes again.

I have an app written for Smartphone using VS 2003.  I was under the
impression that "out of the box" a .NETCF app on Smartphone had single
instance enforcement - meaning if your application is running, and the user
attempts to start it again, the original instance is brought to the front.
My application is not doing this.  Is my understanding incorrect or is there
something addtional I must do to have my app enforce single instance
functionality?

Tim
<ctacke/> - 25 Apr 2006 16:27 GMT
The Windows Mobile platform should be enforcing singleton app behavior.  You
could always use a named mutex to guarantee it yourself (which is what they
should have done in the first place).

-Chris

>I posted this over a week ago and got no response, so here it goes again.
>
[quoted text clipped - 7 lines]
>
> Tim
Tim Wallace - 25 Apr 2006 18:25 GMT
Chris:

Thanks for your reply.  My problem is that the platform isn't enforcing this
behaviour.  Do you have any insight as to what may cause this problem?  I've
not gone out of my way interrupt the standard process.  I basically open a
window with a title bar and a menu.  Then, if I press the Home key (thus
going back to the Today screen) and then attempt to relaunch my app, it is
not brought to the top.  Do I have to code the "bring to top" myself in
response to an event or something?

Tim

> The Windows Mobile platform should be enforcing singleton app behavior.
> You could always use a named mutex to guarantee it yourself (which is what
[quoted text clipped - 13 lines]
>>
>> Tim
<ctacke/> - 25 Apr 2006 18:31 GMT
So is it launching a second instance, of just not bringing the existing
instance to the fore?

-Chris

> Chris:
>
[quoted text clipped - 25 lines]
>>>
>>> Tim
Tim Wallace - 25 Apr 2006 18:45 GMT
Chris:

Actually, I've witnessed two apps running using Task Manager.  I added code
to my app to search for my open window and to bring that window to the front
and close the new app.  This is only successful in closing the new app.  My
existing window is not brought to the fore.  Here is the code I added to my
main method to control this issue:

string appname =
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
splash.lMutex = CreateMutex(IntPtr.Zero, true, appname);
if( !lMutex.Equals(new System.IntPtr(0) ) )
{
   if(Marshal.GetLastWin32Error() == ERROR_ALREADY_EXISTS)
   {
       // need to find the splash window (not posting my actual window
classname or title
       IntPtr hFrmMain = FindWindow("{my_window_classname}",
"{my_window_title}");

       if(hFrmMain != IntPtr.Zero)
       {
           // bring that window to front
           SetForegroundWindow(hFrmMain);

           // exit this application
           return;
       }
       else
       {
           hFrmMain = IntPtr.Zero;
           // check to see if my other window is opened
           hFrmMain = FindWindow("{my_other_window_classname}",
"{my_other_window_title}");
           if(hFrmMain != IntPtr.Zero)
           {
               // bring that window to front
               SetForegroundWindow(hFrmMain);

               // exit this application
               return;
           }
       }
   }
}

// run the app (neither the splash window nor the other window are open)
Application.Run(new splash());

Do you see any logic errors?

Tim

> So is it launching a second instance, of just not bringing the existing
> instance to the fore?
[quoted text clipped - 31 lines]
>>>>
>>>> Tim
Alex Feinman [MVP] - 25 Apr 2006 19:25 GMT
Try using HWND | 0x1 as a parameter to SetForegroundWindow.

> Chris:
>
[quoted text clipped - 84 lines]
>>>>>
>>>>> Tim
Tim Wallace - 25 Apr 2006 20:41 GMT
Alex:

I added the 0x1 to the handle (I had to convert the IntPtr to an Int32, do
the |0x1 and convert back to IntPtr).  Still, not luck.

Tim

> Try using HWND | 0x1 as a parameter to SetForegroundWindow.
>
[quoted text clipped - 86 lines]
>>>>>>
>>>>>> Tim
Tim Wallace - 25 Apr 2006 19:27 GMT
Let me add that the code I added will not bring either of my windows to the
top.

Tim

> Chris:
>
[quoted text clipped - 84 lines]
>>>>>
>>>>> Tim

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.