2 instances of app running--naming

C

cj

I run two instances of an application on a pc at one time. I want them
to assume app A and app B identities.

If I check for a previous instance of the app running when the app
starts I can determine if the app is the first to start or not. If it's
the first it become app A if not app B.

The problem becomes if after both are running app A is shutdown and
restarted. It'll see another instance of the app is running and think
it is app B when if fact the app that was already running is B. How can
I avoid this?

I do not want app B to become app A if app A is shutdown.
 
J

Jeffrey Tan[MSFT]

Hi Cj,

Can you explain to me how your application change to AppA or AppB? Do you
use a "if(first instance) 'AppA' else 'AppB'" clause logic? I assume so.

Regarding your problem, here is a simple solution:
1. You may use a Mutex to control this task.
2. Whenever your application is starting, your application should check for
the existance of Mutex first. If Mutex does not exist, you may just execute
AppA function. Then your application should create Mutex.
3. When the second instance is starting, it will find the existance of
Mutex, so it will start as AppB function instead of AppA.
4. After closing AppA and starting the application instance again, your
application will not see the existance of Mutex. So your application will
run as AppA correctly.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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