When i stop the debugging in windows application the exe of a project
is shown as running in task manager
how to dispose it thru code?
Dispose exe
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Krishna GaradRank #191 · 12.8K reputationPosted Jun 25, 2011, 2:00 AM EDT
private void KillProcess()
{
Boolean isAlive = true;
while (isAlive == true)
{
foreach (Process runningProcess in System.Diagnostics.Process.GetProcesses())
{
if (runningProcess.ProcessName == "name of exe")
{
runningProcess.Kill();
}
else
{
isAlive = false;
}
}
}
}
Amol183 reputationPosted Jun 25, 2011, 2:08 AM EDT
thanks krishna
Krishna GaradRank #191 · 12.8K reputationPosted Jun 25, 2011, 2:09 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Jun 25, 2011, 8:13 PM EDT
The better solution is to figure out why the program does not exit and fix the problem. That way it is possible to avoid making the same mistake in the future.
What type of program is it? Is it a console program or a Windows Forms program or something else? It is probably a Windows Forms program and a form is not being closed.