473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Controlling one instance of the application from another?

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

May 9 '07 #1
4 1415
Via some form of IPC (remoting, WCF, a shared file, sockets, etc etc
etc), yes.

The implementation depends on what you need...

Marc
May 9 '07 #2
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
May 9 '07 #3
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

May 9 '07 #4
Although "one instance only" is a common request, I'm not sure it is
what the OP asked on this occasion?

Marc
May 9 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Paul Tremblay | last post by:
Hi, Is there a way to ensure that only one instance of an application runs on a physical machine. I would want to do this in a cross platform way. One ide I have is to obtain a list of the...
0
by: Jack | last post by:
Windows 2K Pro Access/Excel 2003 Hi there, I have a large number of password protected Excel Workbooks. The files are protected by code that runs when the workbook opens. The code asks the...
6
by: Dmitry Karneyev | last post by:
Hi! I guess this question have been asked a lot of times, but please be tolerant and if you have any ideas share it. The question is: how to make availibale only one instance of application and...
0
by: Joe Harrison | last post by:
Hello. I have an application which I check to see if there is another running instance at startup. If there is another running instance, I set focus to the existing instance. I am using code...
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
1
by: ljh | last post by:
I want to develop an application that can watch for and monitor any instance of Word 2000/2003. I need to be able to write an add-in menu for Word 2000/2003 and capture all keystrokes and mouse...
0
by: PC GROUP | last post by:
C#, VS2005, THREADS Ok. I have to ways to achieve (almost) the same thing. What do i want to do? Control the progress of an operation in a different project of my application. ...
4
by: Dave | last post by:
I have a global.asax file with Application_Start defined and create some static data there and in another module used in the asp.net application and I realize that static data is shared amongst...
0
by: SteelNetNob | last post by:
I am having a problem where I have a COM application that can be run stand-alone and programatically via COM interop. If an instance of the COM application is being run when my .NET application that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.