Force a CF application to close

G

Guest

I'm using the CreateMutex to ensure that only one instance of my vb.net CF
for Windows CE application exists at one time. However, when it detects
another instance attempting to open, the Application.Exit() will not close
the application immediately. In the constructor of my main form, I first
check for multiple instances, and then start a new thread for my splash page.
The problem is, even when the Application.Exit() get called, it still
executes all remaining code in the constructor before actually exiting the
application. Is there a way to force the application to shutdown immediately?
Simply calling frmMain.close() will not work, as the instance validation is
done in a seperate object. Any suggestions?

Thanks in advance.
 
G

Guest

I've tried your suggestion of killing the worker thread, but the application
still hangs. I've used the emulator to step through the code, and this is
what I've found. If it finds another instance of the application running, it
then doesn't even create the worker thread and exits the constructor.
However, once it leaves the constructor, the application is still running,
but the debugger can't follow the execution path. Nothing gets displayed, but
the application is still running indefinately in the background, using 100%
CPU and freezing the emulator until I manually Stop my app with the debugger.

I believe that it is executing some of it's own (native?) code immediately
following the constructor call before returning back to my code. To test this
theory, I put the check for multiple instances and worker thread in the Load
even of frmMain, and it will exit the application properly. This however is
not the desired fix, as I want my splash screen to launch immediately when
the app starts.

Does any of this sound right, and if so, how can I make the app close
immediately in the constructor?

Thanks for your previous feedback.
 
C

Claire

static void Main()
{
// Make sure only a single instance is running
int pCount = 0;
ProcessEntry[] processes = ProcessEntry.GetProcesses();
foreach(ProcessEntry p in processes)
{
if
(p.ExeFile.ToLower(CultureInfo.CurrentCulture).CompareTo(Globals.ApplicationName.ToLower())==0)
pCount++;
}
if (pCount > 1)
{
MessageBox.Show("An instance of this application is already running",
"Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return;
}
Application.Run(new frmMain());
}
 
G

Guest

To resolve this, I used the Main() method. I first check for running
instances, and if there are none, then
Application.Run(frmMain.getInstance()). This way, nothing at all fires if
there is an existing instance.

Claire, your suggestion looks ideal, but it seems the Process and
ProcessEntry objects are not available in the Compact Framework.

Thanks to all who helped.
 
C

Claire

Oops sorry Joseph, you need a copy of the freeby open source OpenNetCF Smart
Device Framework components to do this (OpenNetCF.ToolHelp)
I should have checked my uses. www.opennetcf.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top