multiple versions of exe running - how to manage it so only 1 is running?

I have a console app, which isn't closing properly....i.e.

After closing the console application, the window disappears, but the process is remaining in the task manger

I believe the active X control is responsible, however, I need a way to get rid of it in task manger
When i reopen it/close i end up with multiple versions running in task manger and its causing issues


I would like to add code a line of code which can "kill" the previous running process for the same console application.


I have tried these two cases
Case 1:
 AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); 

 static void CurrentDomain_ProcessExit(object sender, EventArgs e)
        {
            foreach (var process in Process.GetProcessesByName("FlirAdapterConsole"))
            {
                process.Kill();
            }
        }

Open in new window

When I close the console app, this isn't getting called so this doesn't work


Case 2 :
 
 [STAThread]
        static void Main()
        {
            

            foreach (var process in Process.GetProcessesByName("FlirAdapterConsole"))
            {
                process.Kill();
            }

Open in new window

This is supposed to kill any previous instances of the app running in task manager, but instead it actually closes the current app
 

This code is for closing apps that have the name "FlirAdapterConsole"

     foreach (var process in Process.GetProcessesByName("FlirAdapterConsole"))
            {
                process.Kill();
            }

Open in new window


I have tried using these names instead
FlirAdapterConsole.exe
FlirAdapterConsole.exe *32

but the apps do not close

any help appreciated!
websssCEOAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodeCruiserCommented:
Have you tried killing the active x instead? What activex is it?
0
Jacques Bourgeois (James Burger)PresidentCommented:
Instead of trying to kill the previous running instance, it would make a lot more sense to try to find the cause of the problem and solve it so that the application closes properly.

"I believe the active X control is responsible"

"I believe" is never a good way to try to find a solution. You need to make sure before deciding on the proper solution to solve a problem.

If it is indeed a problem with an ActiveX, killing the application in the Task Scheduler risk solving only part of the problem. The ActiveX might still stick in memory, causing a memory leak.

Some dlls require that you call a Quit, Close or some other method before you terminate an application. It is also always a good thing to set an ActiveX object to Nothing when you have finished with it, because the framework will not perform on an ActiveX object the type of cleanup that it does on .NET objects. And if none of this works, you sometimes need to use the ReleaseComObject method in the framework to release an ActiveX.

These are all things that should be tried, all together if needed, before going the "Kill the process" route. And if none of this works, then look carefully at everything that your application does.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.