Click here to get back home

single instance application

 HomeNewsGroups | Search | About
 microsoft.public.smartphone.developer    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
single instance application Tim Wallace 03-22-2006
Get Chitika Premium
Posted by Tim Wallace on March 22, 2006, 11:43 pm
Please log in for more thread options
I have an application written in C# for Smartphone. I was (obviously)
mistaken in thinking that if my app is running and I press the Home key and
then click the icon to start my app again, that the OS would switch to the
already-running application. How does one accomplish this singleton on a
Smartphone (mutex, something else)? This is unknown territory to me on
Smartphone.

Tim



Posted by riki on March 22, 2006, 11:52 pm
Please log in for more thread options
Tim Wallace wrote:
> I have an application written in C# for Smartphone. I was (obviously)
> mistaken in thinking that if my app is running and I press the Home key and
> then click the icon to start my app again, that the OS would switch to the
> already-running application. How does one accomplish this singleton on a
> Smartphone (mutex, something else)? This is unknown territory to me on
> Smartphone.

the c++ wizard uses a names mutex to detect previous instances, then
switches to the old instance using SetForegroundWindow();

riki

----
The history of liberty is a history of the limitation of governmental
power, not the increase of it.-- Woodrow Wilson, 1912
By Night:
ThemeChanger for Smartphone : http://homepages.inspire.net.nz/~gambit/
AbstractStart for Smartphone :
http://homepages.inspire.net.nz/~gambit/AbstractStart/
Latest Betas have WM5 layout and speed dial support

Posted by Tim Wallace on March 23, 2006, 12:23 am
Please log in for more thread options
Riki:

Thanks for your reply, but I've coded this app in C#. I don't see how the
C++ wizard applies. Could you explain further?

Tim

> Tim Wallace wrote:
>> I have an application written in C# for Smartphone. I was (obviously)
>> mistaken in thinking that if my app is running and I press the Home key
>> and then click the icon to start my app again, that the OS would switch
>> to the already-running application. How does one accomplish this
>> singleton on a Smartphone (mutex, something else)? This is unknown
>> territory to me on Smartphone.
>
> the c++ wizard uses a names mutex to detect previous instances, then
> switches to the old instance using SetForegroundWindow();
>
> riki
>
> ----
> The history of liberty is a history of the limitation of governmental
> power, not the increase of it.-- Woodrow Wilson, 1912
> By Night:
> ThemeChanger for Smartphone : http://homepages.inspire.net.nz/~gambit/
> AbstractStart for Smartphone :
> http://homepages.inspire.net.nz/~gambit/AbstractStart/
> Latest Betas have WM5 layout and speed dial support



Posted by riki on March 23, 2006, 12:29 am
Please log in for more thread options
Tim Wallace wrote:
> Riki:
>
> Thanks for your reply, but I've coded this app in C#. I don't see how the
> C++ wizard applies. Could you explain further?

it doesn't directly apply, but you can use the same method. I'm not a c#
guru, but you should be able to create a named mutex to detect previous
instances, and you should be able to do something similar to a
SetForegroundWindow(FindWindow(L"apptitle"))

riki


----
To know the road ahead, ask those coming back.-- Chinese proverb
By Night:
ThemeChanger for Smartphone : http://homepages.inspire.net.nz/~gambit/
AbstractStart for Smartphone :
http://homepages.inspire.net.nz/~gambit/AbstractStart/
Latest Betas have WM5 layout and speed dial support

Posted by Tom Moon on April 7, 2006, 4:21 pm
Please log in for more thread options
Here's the C++ implementation. I'm sure it's easy to re-interpret this
in C#
The C++ Wizard adds a few more bells and whistles to make the Previous
App Instance check more robust. This method works well enough.

// TRUE means we found a previous instance of this program running
// FALSE means we are the only instance running on the system
BOOL IsPrevInstance(void)
{
HWND hwnd;
BOOL fIsPrevInstance = FALSE;

// Create a named event
g_hSingleEvent = CreateEvent(NULL, TRUE, FALSE, g_szClassName);
DWORD err = GetLastError();
if(g_hSingleEvent == NULL)
{
// bad ERROR; we should quit!
return TRUE;
}
// If the event already existed, that means there's
// another copy of our app already running
if(err == ERROR_ALREADY_EXISTS)
{
// We found the named event; now try to find the
// other application window by that name
hwnd = FindWindow(g_szClassName, NULL);
if(NULL != hwnd)
SetForegroundWindow((HWND)((UINT_PTR)hwnd | 0x01));
CloseHandle(g_hSingleEvent);
// we should quit; another instance found!
fIsPrevInstance = TRUE;
}//end if(ALREADY_EXISTS)

return fIsPrevInstance;
}// end IsPrevInstance

-J Tom Moon


Similar ThreadsPosted
Single Instance June 15, 2007, 5:22 am
How to detect the alreayd running instance f any application August 23, 2006, 1:32 am
Re: How to detect the alreayd running instance f any application August 23, 2006, 3:06 am
How to ensure that only one instance of application runs on pocket May 25, 2007, 12:59 am
WM5: can we have a single binary for PPC and SP? August 19, 2005, 4:51 am
One app instance only reactivation issues April 11, 2008, 7:28 am
Supporting both WM5 and WM2003 in a single exe July 14, 2006, 2:23 pm
Instance of media player vs Sendmessage August 29, 2006, 12:14 am
Dynamic Instance list in Perfmon July 14, 2008, 7:02 am
Multiple message on a single event August 30, 2005, 2:34 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap