Re: Issues with multiple instances
- From: "<ctacke/>" <ctacke[@]opennetcf[dot]com>
- Date: Thu, 12 Oct 2006 12:23:02 -0400
I'd definitely like to see a repro of that. Your suggested route is
definitely a safe workaround (though I'd think the first would be safe too).
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--
"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:escsCkh7GHA.4604@xxxxxxxxxxxxxxxxxxxxxxx
There was a report like this in, I think, the last Windows CE chat. It
appears that it might be a problem with using CreateMutex( NULL, TRUE,
name ). It seemed that the poster was saying that he was able to do this
in two programs and get something other than ERROR_ALREADY_EXISTS from
both. I was expecting him to post the repro here, but I didn't see
anything wrong with the code and suggested that he try getting the mutex
without trying to take ownership and use WaitForSingleObject() to get it,
timing out and exiting if that didn't return in a second or two.
Paul T.
"<ctacke/>" <ctacke[@]opennetcf[dot]com> wrote in message
news:%239XoIYf7GHA.4620@xxxxxxxxxxxxxxxxxxxxxxx
If you're using a named mutex properly, I can't see how it's possible to
have multiple instances running. Show us some code. "Running Programs"
shows all top-level windows (so all forms) in your app - not actual
processes.
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--
"Guus Davidson" <GuusDavidson@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0B4E9FF7-823B-4003-A043-81DD47D089DF@xxxxxxxxxxxxxxxx
Hi,
I have implemented a named mutex as suggested in one of the earlier
postings, but I am still able to create multiple instances of my
application.
I have added in a log4net logging framework to see if it will help me
track
down where the issue is.
I have my logging setup so that it should just append to the log file.
I have set up my application so that on the device it can be started by
pressing one of the hardware buttons.
My test here is to press the button a couple of times and then while
everything is loading up check out the "running applications".
From my log file I am only ever seeing one entry point into the "Main"
method, yet I can clearly see that there are several instances of my
application running in the running application list.
I have enclosed the relivent code snippets from my application, could
anyone
tell me what I am doing wrong ?
thanks in advance
Guus Davidson
<Code Snippet from my application>
//My main method using the IsInstanceMethod, this creates a named mutex
is
one doen't exist.
//I am passing back a reference to metex handle so I can release the
mutex
when I am finished.
//I have added in log4net and am using a singleton logger within my
application.
static void Main()
{
iLog.Info("Main");
int mutexhandle = 0;
if (!IsInstanceRunning(ref mutexhandle))
{
// just making a local copy due to threading fears
int mutexhnd = mutexhandle;
// Wait until it is safe to enter.
if (IsActivateProperly())
{
Application.Run(new MainForm());
}
else
{
Application.Run(new RegistrationForm());
}
if (ReleaseMutex(mutexhnd))
{
iLog.Info("mutex released");
}
}
iLog.Info("~Main");
}
//MainForm constructor, the bugs comment isn't mine its dirty coding and
needs removed.
public MainForm()
{
iLog.Info("MainForm constructor");
this.Enabled = false;
//bugs: it will throw an ArgumentException given the app.config file is
not
in place
System.Threading.Thread.Sleep(500);
InitializeComponent();
iLog.Info("~MainForm constructor");
}
//My Splash screen start method, called as a result of the
splashFormThread
in the MainForm_Load
public void StartSplash()
{
iLog.Info("StartSplash");
if (iSplashForm == null)
{
iSplashForm = new SABannerForm();
}
iLog.Info("running splash");
Application.Run(iSplashForm);
iLog.Info("~running splash");
iLog.Info("~StartSplash");
}
private void CloseSplash(object stateinfo)
{
iLog.Info("CloseSplash");
if (iSplashForm != null)
{
iLog.Info(iClassName + " Closing splash form");
// Shut down the splash screen
iSplashForm.Invoke(new EventHandler(iSplashForm.KillMe));
iSplashForm.Dispose();
iSplashForm = null;
}
iLog.Info("~CloseSplash");
}
private void MainForm_Load(object sender, System.EventArgs e)
{
iLog.Info("MainForm_Load");
try
{
#region start the splash screen
iLog.Info("Start Splash Thread");
Thread splashFormThread = new Thread(new ThreadStart(StartSplash));
splashFormThread.Priority = ThreadPriority.AboveNormal;
splashFormThread.Start();
#endregion
#region initialize all my other stuff is set up here
..
..
..
..
}
catch (Exception ex)
{
iExhandler.Error("MainForm: " + ex.ToString());
}
iLog.Info("~MainForm_Load");
}
// editied version of a method found on form somewhere
// thought I need to releasethe mutex once I've created it so am passing
back the handle
public static bool IsInstanceRunning(ref int aMutexHandle)
{
string appname =
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
iLog.Info(appname + "IsInstanceRunning");
aMutexHandle = CreateMutex(IntPtr.Zero, true, appname);
bool result = false;
if (aMutexHandle != 0)
{
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
iLog.Info(appname + " application does exist");
result = true;
}
}
iLog.Info(appname + "~IsInstanceRunning");
return result;
}
.
- References:
- Re: Issues with multiple instances
- From: Daniel Moth
- Re: Issues with multiple instances
- From: Guus Davidson
- Re: Issues with multiple instances
- From: <ctacke/>
- Re: Issues with multiple instances
- From: Guus Davidson
- Re: Issues with multiple instances
- From: <ctacke/>
- Re: Issues with multiple instances
- From: Paul G. Tobey [eMVP]
- Re: Issues with multiple instances
- Prev by Date: Re: Synchronize files/folders programmatically
- Next by Date: Re: Synchronize files/folders programmatically
- Previous by thread: Re: Issues with multiple instances
- Next by thread: Zip Lib for CF 1.1
- Index(es):
Relevant Pages
|