 |
|
|
 |
|
|
You must be checking in debugger with VS2005 or VS2008. It is because of Hosting Process SingleInstance.vshost.exe created along with SingleInstance.exe. If you directly run the application without debugger you will see, application is working correctly.
Check following link to disable the Hosting Process- http://msdn.microsoft.com/en-us/library/ms185330(VS.80).aspx[^]
Manish Agarwal manish.k.agarwal @ gmail DOT com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thank you very much. Excuse me for my poor english. You are right, Hosting Process SingleInstance.vshost.exe created.But it does not work.
I add MessageBox as below: foreach(Process _process in processes) { MessageBox.Show(string.Format("ID={0}\nName:{1}\nHandle{2}",_process.Id,_process.MainModule.FileName,_process.MainWindowHandle)); if (_process.Id != process.Id && _process.MainModule.FileName == process.MainModule.FileName && _process.MainWindowHandle != IntPtr.Zero) { hWnd = _process.MainWindowHandle; break; } }
In no-debug mode,I find all of the first and second process's MainWindowHandle are 0.Why? My ide is VS2008.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I have tested with VS2005 working fine. Currently I don't have VS2008 setup with me .
Manish Agarwal manish.k.agarwal @ gmail DOT com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks again. Lead to the reasons for this phenomenon is a set of "ShowInTaskbar=false". This problem can be solved?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
In this case MainWindowHandle will be NULL so the current code will not bring the already running process in focus but there will be only one instance.
Manish Agarwal manish.k.agarwal @ gmail DOT com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
I have to open application when a file (.ext) is clicked (File is associated with that application like .doc with WINWORD).
Application should be single instance. When I click the .ext file it should open the application with that content. If an instance is runnig it should ask the user whether you want to close this application and then open the new .ext file.
Need help in C#.
Thanks Surya
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
When an extension is associated with an application and user click on a file with that extension, the file name is passed as a command line argument. You can look for the command line argument at launch time and process the request accordingly. But this need be done before SingleInstance.SingleApplication.Run(new FrmMain());
Manish Agarwal manish.k.agarwal @ gmail DOT com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Manish,
Thanks for the reply.
When I click on .ext file for the second time i.e already an instance is running. Now the clicked .ext file should be opened in the application.
Can you please tell me how to do it?
Thank You, Surya
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
For this you have implement some shared memory. Where you can write the shared argument (file name) and some way to notify the first process that something is there in shared memory to process.
Manish Agarwal manish.k.agarwal @ gmail DOT com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Thank You Sir.... This is what I need........
Sagar Pattnayak Software Developer Sun-Dew Solutions +91-9831169962
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
this code is working great but more than it demands, as it prevents another instances of the application even for another users can anyone help me to make it run application single instance for any number of users
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
For this you need to remove "Global\\" from line "mutex = new Mutex(true, "Global\\"+sExeName, out bCreatedNew);" of IsAlreadyRunning() in SingleInstance.cs in function while creating a mutex name.
Manish Agarwal manish.k.agarwal @ gmail DOT com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
The code is working great for me, except for one thing. When my original instance is minimized to the system tray (the form's visible property is false) and I open the second instance, the original instance stays in the tray, the form is not visible. Does anyone have any advise on the best way to open it?
My app only minimizes to the system tray when the main form is closed (if that matters). Here is the code that I have for the closing event of the main form, it's pretty basic: private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (this.Visible) { e.Cancel = true; this.Visible = false; } }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
try this one. You should add a notify control to your main form.
private void MainForm_Closing(object sender,system.ComponentModel.CancelEventArgs e) { this.MainForm.Hide(); notifyIcon1.visible=true(); }
private void notifyIcon1_DoubleClick(object sender, EventArgs e) { this.notifyIcon1.visible=true(); this.MainForm.show(); }
//hope this help.
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Thanks for the help, but I already have the notify icon. The issue I'm having is with the SingleApplication class and the SingletonApplication class not automatically opening the 'Original instance' of my application.
This happens when I try to run a 'second instance' of my application and the 'Original instance' is only displayed as a notify icon in the system tray. Otherwise it works fine in all other situations. I hope that is more clear.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
There are a couple of changes I suggest:
1. In function IsAlreadyRunning() the code gets the executing assembly. Once you package this code into a library, the running assembly at the point of call is the dll, not the app, so it misbehaves, allowing only one instance of the library to be used, even though you may have multiple different apps using it. My workaround was to use string strLoc = Application.ExecutablePath instead. 2. Windows XP + Visual Studio 2005 have some bug: if you start one instance of an app, and then a second instance, the fileInfo name in the one case has a lowercase .exe while the other has an uppercase .EXE. So they become different mutexes. I suggest normalizing the string string sExeName = fileInfo.Name.ToLower();
3. I thought the wrong methods were exposed by the library. If you call Run(new MyForm()) then your form gets eagerly constructed before you test if if your app is already running. I think it is more sensible to expose the function IsAlreadyRunning, so that the client can say if (SingleApplication.IsAlreadyRunning()) return; Application.Run(new MyForm()); ...
peter
peterw
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks Peter for your suggestions. I will takecare of these in my next change.
Manish Agarwal manish.k.agarwal @ gmail DOT com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Why not just create a function like the following?
Private Function AppIsAlreadyRunning as Boolean If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then Return True Return False End Function
Maybe I'm missing something....
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |