Link to home
Start Free TrialLog in
Avatar of the_b1ackfox
the_b1ackfoxFlag for United States of America

asked on

A process to kill...

I have written an application in c# 2003 which uses multiple winforms forms stored in memory.  The problem is that during the course of a day, there seem to be some of the forms left in memory.  I would like my application to check if an instance of the application is already loaded, and if so, then kill the existing process.
Avatar of Gautham Janardhan
Gautham Janardhan

System.Diagnostics.Process Fpc =
                System.Diagnostics.Process.GetProcessesByName
                (System.Diagnostics.Process.GetCurrentProcess().ProcessName);
            if (Fpc.Id != System.Diagnostics.Process.GetCurrentProcess().Id)
            {
                Fpc.Kill();
            }
SOLUTION
Avatar of bungHoc
bungHoc
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of the_b1ackfox

ASKER

I am evaluating both solutions and will award points accordingly
BungHoc, I couldn't get your solution to work.  Not sure where it is off.