Search the web
Sign In
New User? Sign Up
codesnips · Code Snippets
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Single Instance apps   Message List  
Reply | Forward Message #39 of 48 |
RE: [codesnips] Single Instance apps

assume 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 apps

 
hi,
 
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 window                 
if(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.


Mon Jul 21, 2003 12:01 pm

asimletters
Offline Offline
Send Email Send Email

Forward
Message #39 of 48 |
Expand Messages Author Sort by Date

hi, 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...
fahad
desperate_de...
Offline Send Email
Jul 21, 2003
10:41 am

assume 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...
Asim
asimletters
Offline Send Email
Jul 21, 2003
11:58 am

Messagei 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...
fahad
desperate_de...
Offline Send Email
Jul 21, 2003
1:42 pm

and I think that asim is talking about sessions, not processes. They both are altogether different things. The operating system also maintain a separate...
Nauman Leghari
laghari78
Online Now Send Email
Jul 21, 2003
6:26 pm

and I think that asim is talking about sessions, not processes. They both are altogether different things. The operating system also maintain a separate...
Nauman Leghari
laghari78
Online Now Send Email
Jul 21, 2003
6:26 pm

Hmmm. But still windows messenger that comes with XP, allows multiple users to use it at the same time (it may use the same thread I donno abt that.) It shows...
Faraz Beg
baigsaab22
Offline Send Email
Jul 22, 2003
6:12 am

I dont think so. You can run MSN messenger with Windows XP Messenger but you can't run two different instances for each application. They both are implemented...
Nauman Leghari
laghari78
Online Now Send Email
Jul 22, 2003
4:00 pm

What I'm talking abt is the scenario in which multiple users (say a couple of them) log into an XP workstation and all have msn logged in. although there's...
Faraz Beg
baigsaab22
Offline Send Email
Jul 22, 2003
9:10 pm

MessageIf we are using this code in our application and multiple users are logged in using remote desktop,Individual user cant be able to run multiple instance...
Owais Anwer
owais@...
Send Email
Jul 22, 2003
10:23 am

Messagefriends, i didnt CHECKED that code on the case(s) you guys specified... and i dont have resources to check this as well... if you have resources, you...
fahad
desperate_de...
Offline Send Email
Jul 23, 2003
6:19 am

MessageThe scenario you are talking about is base on different sessions. When a user log into a XP workstation it's session is created ,Means each user has...
Owais Anwer
owais@...
Send Email
Jul 23, 2003
7:53 am
< Prev Topic  |  Next Topic >
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help