Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CeRunAppAtEvent / Mutex

31 views
Skip to first unread message

Miguel

unread,
Sep 19, 2005, 8:53:55 AM9/19/05
to
I am experiencing the following problem.
F.e.
I want to run an application on the wakeup event of the mobile device.
I only want one instance of the application running at the given time (
single process).
The application itself just shows something on the screen, which is not
relevant to the problem.
CeRunAppAtEvent seemed to solve the problem.
However at wakeup, a new instance of the application is started.
Is there an easy solution to overcome this (perhaps by mutex or event)
an how do I have to implement this feature?

Regards

Chris Tacke, eMVP

unread,
Sep 19, 2005, 9:43:17 AM9/19/05
to
Correct, the answer is with a mutex. At app startup check for the mutex, if
it's already taken you need to shut down the current instance and activate
the other. A thread in the app specifically waiting for such an event is a
good mechanism for this.

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate


"Miguel" <miguel...@telenet.be> wrote in message
news:1127134435.1...@g49g2000cwa.googlegroups.com...

Miguel

unread,
Sep 20, 2005, 6:33:10 AM9/20/05
to
I'm rather new to mutex.
Could you provide a small example how to achieve this?
I'd be grateful

Regards

Sergey Bogdanov

unread,
Sep 20, 2005, 7:29:01 AM9/20/05
to
See this example [1] which demonstrates how to create a single instance
application by using named events. For mutexes the idea is the same.

[1] http://www.sergeybogdanov.com/Samples/SPSingleInstance.zip


--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

Miguel

unread,
Sep 20, 2005, 8:36:29 AM9/20/05
to
My application is not a graphical one
It's merely an application that does some stuff in the background

Will this work aswell, since you're working with FindWindow (and there
isn't)

Regards

Sergey Bogdanov

unread,
Sep 20, 2005, 8:42:37 AM9/20/05
to
This will work as well it doesn't matter what application you have. The
main part of the code is:

IntPtr evnt = CreateEvent(IntPtr.Zero, false, false, AppNamedEvent);
if (Marshal.GetLastWin32Error() != 0)
{
// one instance of application is run,
// do work
}
...

CloseHandle(evnt);

--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

0 new messages