473,320 Members | 1,868 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,320 software developers and data experts.

How to open the already running application

Hi,

I have a windows form application, where the requirement is as
follows...

If the application is already running, and the user tries to open
another instance of the application, the already running instance of
the application should be activated.

Also my application can be in the system tray (and not be present in
the taskbar), so even in this condition the application should be
activated (i.e. application's main screen should be displayed)

Any help in this regard is appreciated.
Regards,
Ankit!
Jun 27 '08 #1
5 2762
On May 30, 9:10*am, aagarw...@gmail.com wrote:
Hi,

I have a windows form application, where the requirement is as
follows...

If the application is already running, and the user tries to open
another instance of the application, the already running instance of
the application should be activated.

Also my application can be in the system tray (and not be present in
the taskbar), so even in this condition the application should be
activated (i.e. application's main screen should be displayed)

Any help in this regard is appreciated.

Regards,
Ankit!
Hi,

You have to use something to detect that the app is running already,
take a look at Mutex
To activate the prev. instance you have to get the hWnd of it and make
it the foremost window. Look in the archive of this NG as this is a
recurrent question
Jun 27 '08 #2
On Fri, 30 May 2008 06:10:49 -0700, <aa*******@gmail.comwrote:
I have a windows form application, where the requirement is as
follows...

If the application is already running, and the user tries to open
another instance of the application, the already running instance of
the application should be activated.

Also my application can be in the system tray (and not be present in
the taskbar), so even in this condition the application should be
activated (i.e. application's main screen should be displayed)
As Ignacio says, you can use a named Mutex to detect the case. As for how
to actually perform the activation, AFAIK there's nothing in .NET that
allows you to do this. You'll need to use p/invoke with the
SetForegroundWindow() function, and of course that means you'll have to
actually find the correct window, also via p/invoke (again, AFAIK there's
nothing in .NET to allow you to enumerate top-level windows from other
processes).

There are restrictions on whether your own process will be allowed to
bring the other window to the foreground. When it can't, the window entry
in the task bar will flash instead, which is correct behavior. However,
most likely the new instance of the application will be the foreground
task and will have the rights to bring the other application to the
foreground, so I think that normally this will do exactly what you want.

Pete
Jun 27 '08 #3
thanks for the inputs Michael...

However, i was looking forward to an IPC solution. Any leads in that
regard?

Ankit!!
Jun 27 '08 #4
On Sun, 01 Jun 2008 20:59:53 -0700, <aa*******@gmail.comwrote:
thanks for the inputs Michael...

However, i was looking forward to an IPC solution. Any leads in that
regard?
In .NET, network i/o (e.g. Socket, UdpClient, TcpClient) is the usual
solution. I have read comments that said they added named pipes to .NET
in the latest version, but I haven't looked into that. Named pipes can be
slightly more convenient, but either approach should work fine.

Keep in mind that using IPC, you're probably anticipating the application
in question trying to restore itself. As I mentioned before, there are
strict rules about when an application can actually be forced to the
foreground. Those rules generally preclude an application forcing itself
to the foreground. If that's important to you, you are actually likely to
be better off having the current foreground application (the newly-started
instance of the same application) handle bringing the other to the
foreground.

Pete
Jun 27 '08 #5
On Jun 1, 8:59 pm, aagarw...@gmail.com wrote:
thanks for the inputs Michael...

However, i was looking forward to an IPC solution. Any leads in that
regard?
Look at the MSDN remoting documentation to get started:
http://msdn.microsoft.com/en-us/libr...07(VS.80).aspx

Peter mentioned the possibility of using network channels rather than
named pipes. This page addresses that choice:
http://msdn.microsoft.com/en-us/libr...t2(VS.80).aspx

Michael
Jun 27 '08 #6

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

Similar topics

0
by: Huw Lloyd | last post by:
I am sure this must be easy but i have an application that has a number of forms which can all be open at the same time. When i open a form from a menu i want to check to see if the form is open...
6
by: Stefania Scott | last post by:
Hi, I need to find how can I know that a program I am going to shell it is already open. This program uses an csv file that I need to refresh before shelling the program, however if the csv file...
22
by: Nina | last post by:
While user is working on a windows application, at same time he or she launches another instance of the same application. Will this affect the global variables in the first instance of this...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
3
by: bobdydd | last post by:
Hi Everybody Access 2000, Outlook 2000 Windows XP I am running the code below to open Microsoft Outlook from a Command Button. It works fine until I tried it on a machine that has Office...
5
by: Ryan Liu | last post by:
Hi, Both way works, I'd just ask some experts which way is better? My application creates a log file daily. Now each time when I write a log, I will open the file and append to the end....
1
by: keri | last post by:
Hi, I use the below for the user to view their outlook calendar Sub DisplayInbox() Dim myolApp As Outlook.Application Dim myNameSpace As Outlook.NameSpace Dim myFolder As Outlook.MAPIFolder...
25
by: Andy_Khosravi | last post by:
I just recently changed my database that I'm running from a monolithic DB to a split FE/BE. The front end resides on the client machine and the BE resides on a network drive. I'm experimenting with...
0
by: Swys | last post by:
Hi there, I am currently trying to write myself a wrapper class for the Excel interop services. I had a problem on closing the process, but just decided to kill it in the end. My current problem,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.