and I think that asim is talking about sessions, not processes. They both are altogether different things. The operating system also maintain a separate session for each logged-in user. In the case of Operating system sessions, (in my opinion) they are not shared. "Multiuser" capability is added as a facility to the operating system and It is an enhancement over existing OS which are single user.
The usability of the code that fahad sent is comparable with the functionality of Microsoft MSN Messenger which restricts itself to just one instance.
-----Original Message-----
From: fahad [mailto:desperate_desperado@...]
Sent: Monday, July 21, 2003 2:48 PM
To: codesnips@yahoogroups.com
Subject: Re: [codesnips] Single Instance appsi think processes are managed by OS on machine leve not the at the user level in case of a remote desktop connection ...it will work if a user, say user A is logged in and invoke the Application at some time "Ta" which is greater than "Tb" (the time when user B invokes the same Application)... then user B will get the instance of the app that was invoked by user A...it would be really a chance ofTa = Tb...so it will wUrk.... 99.9%----- Original Message -----From: AsimSent: Monday, July 21, 2003 5:01 PMSubject: RE: [codesnips] Single Instance appsassume that 2 users are logged in, on a single machine (through remote desktop connection), and both the users try to run an instance of the app, will this code wurk ??Thanks,Asim-----Original Message-----
From: fahad [mailto:desperate_desperado@...]
Sent: Monday, July 21, 2003 3:46 PM
To: codesnips@yahoogroups.com
Subject: [codesnips] Single Instance appshi,this is my first post to this group.... its about forcing your app to have only one instance running..you need to import 2 dlls to find a window and to set focus to that window
/////////
[DllImport("User32",EntryPoint="FindWindow")]
private static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport("User32",EntryPoint="SetForegroundWindow")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[STAThread]
static void Main()
{
Process ThisProcess = Process.GetCurrentProcess();
Process [] AllProcesses = Process.GetProcessesByName(ThisProcess.ProcessName);
if (AllProcesses.Length > 1) // if the process is running
{
bool ret;
IntPtr hWnd = FindWindow(null, "Form1"); //the caption of your windowif(hWnd != IntPtr.Zero)
{
ret = SetForegroundWindow(hWnd); // give focus to this window//you can also use BringWindowToTop instead of this
}
}
else
{//run the new process
Application.Run(new Form1());
}
}
To unsubscribe from this group, send an email to:
codesnips-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
To unsubscribe from this group, send an email to:
codesnips-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
To unsubscribe from this group, send an email to:
codesnips-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.