Re: Avoid double execution of a program
- From: Sergey Bogdanov <sergey.bogdanov@xxxxxxxxx>
- Date: Tue, 07 Jun 2005 21:04:31 +0300
Yep, carefully see the example [1]:- CreateEvent is:
[DllImport("coredll.dll", EntryPoint="CreateEvent", SetLastError = true)]
private static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, string lpName);
[1] http://www.sergeybogdanov.com/Samples/SPSingleInstance.zip
-- Sergey Bogdanov http://www.sergeybogdanov.com
Saverio Tedeschi wrote:
Hi Sergey;
CreateEvent is not supported in my version of CF, as only GetEvents and GetProperties are supported as methods of System.ComponentModel.TypeDescriptor. Did I take the wrong way or am I overlooking something? TIA.
"Sergey Bogdanov" <sergey.bogdanov@xxxxxxxxx> ha scritto nel messaggio news:%23wlSkc4aFHA.2664@xxxxxxxxxxxxxxxxxxxxxxx
The example demonstrates how to use named event and does not depend from the main form:
IntPtr evnt = CreateEvent(IntPtr.Zero, false, false, AppNamedEvent); if (Marshal.GetLastWin32Error() != 0) { // one instance of application is run, activate it IntPtr hwnd = FindWindow(null, "Form1"); if (hwnd != IntPtr.Zero) { SetForegroundWindow(hwnd); }
return; }
As you can see it will activate the main form if it exists and exit all the same.
-- Sergey Bogdanov http://www.sergeybogdanov.com
Saverio Tedeschi wrote:
Thank you Sergey, for your reply.
The problem is, referees try to call program twice (or three times, or four) before it can display a form, for it needs to do some housekeeping. I immediately spawn a secondary task to display splash screen, but it has not the name of the main form, and more, it closes by itself after 10 seconds (housekeeping takes abot 12 secs on a 200MHz XScale processor, or on a 400 forced to 200 for battery-lasting purposes). I appreciate your clue anyway.
"Sergey Bogdanov" <sergey.bogdanov@xxxxxxxxx> ha scritto nel messaggio news:eoQY7O3aFHA.720@xxxxxxxxxxxxxxxxxxxxxxx
Here is an example how to create a named event to accomplish the single instance behaviour for your application in SmartPhone. This code snippet should work for PPC either:
http://www.sergeybogdanov.com/Samples/SPSingleInstance.zip
-- Sergey Bogdanov http://www.sergeybogdanov.com
Saverio Tedeschi wrote:
Thank you, Chris, for your reply.
Useless to say, I'm moving my first steps into inter-program and inter-task syncronization, so pls forgive me if I'm bothering you.
However, I can't find how2 create a named mutex in VS 2003 (CF 1.0 SP2), as there's only an "Already owned" parameter in New function. Should I create a Win32-wrapper? Where can I find C# or VB declaration for PPC2002/2003 targets? TIA
"Chris Tacke, eMVP" <ctacke@xxxxxxxxxxxxxxxxxxxxxx> ha scritto nel messaggio news:uoG2u81aFHA.3048@xxxxxxxxxxxxxxxxxxxxxxx
A semaphore is not something useful in this case. A mutex is, hence the recommendation.
-- Chris Tacke Co-founder OpenNETCF.org Has OpenNETCF helped you? Consider donating to support us! http://www.opennetcf.org/donate
"Saverio Tedeschi" <tesis@xxxxxxxxx> wrote in message news:%23Vzhak1aFHA.3736@xxxxxxxxxxxxxxxxxxxxxxx
Hi Chris,
thank you 4 your reply. What about CreateSemaphore function? Easier, tricker, harder? TIA
"<ctacke/>" <ctacke_AT_OpenNETCF_com> ha scritto nel messaggio news:OTpa500aFHA.3572@xxxxxxxxxxxxxxxxxxxxxxx
You need to grab a named mutex at app startup. If it already exists, the app is already running so exit. Search the archives for CreateMutex and/or single instance.
-Chris
"Saverio Tedeschi" <tesis@xxxxxxxxx> wrote in message news:e1MkMe0aFHA.3848@xxxxxxxxxxxxxxxxxxxxxxx
Hi all gurus,
forgive me if I'm bothering you. My .NET CF app is designoed to be executed once in target PDAs. However, in customers' hands (actually, refereees) it seems they are able to spawn app more than once, as I receive errors on table locking and replying "OK" the app opens the table, while the design is to loop in opening retries, and a certain numbers of little (?) malfunctioning routines like this one. Even if this (most time) does not lock the execution, there error messages are annoying and, the most important thing, confusing. I guess that in the time the app performs some inizialization, users are apple to launch it a couple of times, tapping on HW button associated. How can I avoid this (kkep in mind that for a couple of seconds nothing appear on PDA's screen. Can some1 point me to the right direction? TIA!
.
- Follow-Ups:
- Re: Avoid double execution of a program
- From: Saverio Tedeschi
- Re: Avoid double execution of a program
- From: Saverio Tedeschi
- Re: Avoid double execution of a program
- References:
- Avoid double execution of a program
- From: Saverio Tedeschi
- Re: Avoid double execution of a program
- From: <ctacke/>
- Re: Avoid double execution of a program
- From: Saverio Tedeschi
- Re: Avoid double execution of a program
- From: Chris Tacke, eMVP
- Re: Avoid double execution of a program
- From: Saverio Tedeschi
- Re: Avoid double execution of a program
- From: Sergey Bogdanov
- Re: Avoid double execution of a program
- From: Saverio Tedeschi
- Re: Avoid double execution of a program
- From: Sergey Bogdanov
- Re: Avoid double execution of a program
- From: Saverio Tedeschi
- Avoid double execution of a program
- Prev by Date: Re: Convert DateTime to XML date type
- Next by Date: Re: Two Showdialog bug?
- Previous by thread: Re: Avoid double execution of a program
- Next by thread: Re: Avoid double execution of a program
- Index(es):
Relevant Pages
|