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!
websssAsked:
Who is Participating?
 
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
 
CodeCruiserCommented:
Have you tried killing the active x instead? What activex is it?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.