 |
|
|
 |
|
 |
Can you elaborate your problem little bit more. Is it related my posted code or a general problem.
Manish Agarwal manish.k.agarwal @ gmail DOT com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thank you for reply. sorry for my poor English.
if i hide my form like
this.Hide();
how can i show my running applications main form when user double click the application again. i really need this ..
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
i have this problem too, are there any solutions, i want create a listener, where the original instance start if a file or somethins is created....
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Very simple and elegant solution, worked great for me the first time I tried it. And without any reference to any VB compatibility namespace! Really appreciate this a lot! - SC59
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
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 | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
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 | 1.00/5 (2 votes) |
|
|
|
 |
|
 |
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 | |
|
|
|
 |
|
 |
Removing "Global\\" will make it run for other users. However an 'Access Denied' exception will be thrown in case a different user has an instance open and we're trying to open a second instance (third in total). I had to add a code that checks the owner of the process and only try to activate a window of a process belonging to the current user. The code to check for a process owner can be found here: http://benreichelt.net/blog/2006/01/31/get-process-user-name/[^].
I added the check for the process owner to GetCurrentInstanceWindowHandle():
string currentProcessOwner = GetProcessOwner(process.Id);
IntPtr hWnd = IntPtr.Zero; foreach (Process proc in processes) { string processOwner = GetProcessOwner(proc.Id); if (processOwner == currentProcessOwner) { if (proc.Id != process.Id && proc.MainModule.FileName == process.MainModule.FileName && proc.MainWindowHandle != IntPtr.Zero) { hWnd = proc.MainWindowHandle; } } } Hope this helps.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
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) |
|
|
|
 |