PC Review


Reply
Thread Tools Rate Thread

Controlling one instance of the application from another?

 
 
melon
Guest
Posts: n/a
 
      9th May 2007
Let's say I have a program.exe file. When I run it, one instance of
it will be created.

If I run it again, then another instance will be created. Question
is, is it possible for instance #2 to issue command to instance #1, or
vice versa?

Thanks

 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      9th May 2007
Via some form of IPC (remoting, WCF, a shared file, sockets, etc etc
etc), yes.

The implementation depends on what you need...

Marc


 
Reply With Quote
 
=?Utf-8?B?Q2hha3JhdmFydGh5?=
Guest
Posts: n/a
 
      9th May 2007
There are many-a-ways to achieve that...
1) You can use Mutex
2) At the program constructor, trace the process that are currently running
on the system, take either name or id of the application and compare with the
current.. application.

If you need more details with code, ping me back..

HTH
--
Every thing is perfect, as long as you share!!!

Don''t forget to rate the post


"Marc Gravell" wrote:

> Via some form of IPC (remoting, WCF, a shared file, sockets, etc etc
> etc), yes.
>
> The implementation depends on what you need...
>
> Marc
>
>
>

 
Reply With Quote
 
=?Utf-8?B?Q2hha3JhdmFydGh5?=
Guest
Posts: n/a
 
      9th May 2007
Using the process as below

First create a method to get the instance is already running or not as below

using System.Diagnostics;

public static Process PriorProcess()
{
Process curr = Process.GetCurrentProcess();
Process[] procs = Process.GetProcessesByName(curr.ProcessName);
foreach (Process p in procs)
{
if ((p.Id != curr.Id) &&
(p.MainModule.FileName == curr.MainModule.FileName))
return p;
}
return null;
}

Now by using this, you can check at the Main method as

static void Main() // args are OK here, of course
{
if (PriorProcess() != null)
{
MessageBox("Another instance is already running.");
return;
}
Application.Run(new Form1()); // or whatever was here
}

Regarding Mutex usage... if you can do R&D that's great. But if you want me
to post the details here will do that...

HTH and don't forget to rate the post

--
Every thing is perfect, as long as you share!!!

Don''t forget to rate the post


"melon" wrote:

> Let's say I have a program.exe file. When I run it, one instance of
> it will be created.
>
> If I run it again, then another instance will be created. Question
> is, is it possible for instance #2 to issue command to instance #1, or
> vice versa?
>
> Thanks
>
>

 
Reply With Quote
 
Marc Gravell
Guest
Posts: n/a
 
      9th May 2007
Although "one instance only" is a common request, I'm not sure it is
what the OP asked on this occasion?

Marc


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
getting extra excel instance when controlling from access VBA =?Utf-8?B?RHVhbmUgV2lsc29u?= Microsoft Excel Programming 2 14th Oct 2005 05:49 AM
Multi-instance vs single instance application kathy Microsoft C# .NET 3 7th Jan 2004 11:53 PM
Controlling an already running instance of Outlook Simmy Microsoft Outlook Program Addins 0 21st Aug 2003 05:01 PM
Controlling an already running instance of Outlook Simmy Microsoft Outlook VBA Programming 0 21st Aug 2003 05:01 PM
Controlling existing IE instance Antonio Villanueva Windows XP Internet Explorer 0 11th Aug 2003 05:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:02 AM.