Re: Avoid double execution of a program

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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!






.



Relevant Pages

  • Repeatable hard crash with 2.6.0.test[123]
    ... One application will reliably cause the system to crash when it exits ... This app worked fine and exited correctly ... the few changes needed to get the 2.kernels running. ... # ACPI Support ...
    (Linux-Kernel)
  • Re: Schannel and Session Renegotiation
    ... Schannel does not support the server sending app ... We are discussing the option of providing support for the client blowing off ...
    (microsoft.public.platformsdk.security)
  • Re: local time for remote users
    ... formatting depend on the UICulture and Culture info you set for the ASP.NET ... Stored a static timezone offset in web.config file and retrieve it at ... Microsoft MSDN Online Support Lead ... Everything was fine until the client decided to use the app for its ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Unable to copy file. ... Access to the path ... is denied.
    ... not used by any other app. ... references are put in by VS2005 I do not use the resx files. ... ** it the service app used(configured in windows Service manager) when you ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.vsnet.general)
  • Re: Service Principal Name in Kerberos
    ... specific account with enabled 'Account is trusted for delegation', ... opens IE and accesses the Client App on IIS that then accesses the Server ... Windows Server 2003 or Windows Vista ... Microsoft Online Community Support ...
    (microsoft.public.platformsdk.security)