By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,659 Members | 910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,659 IT Pros & Developers. It's quick & easy.

Disposing Question

P: n/a
I have a program with windows forms and after execution of my program
im making it invisible for working background progress and i have a
dispose function like this

protected override void Dispose(bool Disposing)
{
if (Disposing)
{
if (components != null)
{
components.Dispose();
}
}
Process[] procuo = Process.GetProcesses();
for (int i = 0; i < procuo.Length; i++)
{

if(procuo[i].ProcessName.Equals("client"))
{
procuo[i].Kill();
}
}

base.Dispose(true);

}
if i close the program normally(pressing X before it become invisible)
its normally closing the client.exe but if i kill it from task manager
its not closing the client.exe how can i do that?
Thanks
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Task manager has two modes of shutting an application down: End Task, which
sends a WM_QUIT message to the foreground window, and End Process which
calls TerminateProcess for the process.

TerminateProcess is a nasty way to shut down an app, basically all the
threads are stopped in their tracks, the DLLs unloaded and the process
closed. Your application does not have the opportunity to handle this
scenario.

From MSDN:
Terminating a process does not cause child processes to be terminated.

Neither the process nor any DLLs attached to the process are notified that
the process is terminating. A process cannot prevent itself from being
terminated.

So basically, since you appear to want to close child processes in your
application when the process is terminated, you can't. You could have your
application act as a remoting host, and if the child processes can't connect
every so often they close themselves down.

"Dakkar" <da****@sylveria.gen-dot-tr.no-spam.invalid> wrote in message
news:42********@127.0.0.1...
I have a program with windows forms and after execution of my program
im making it invisible for working background progress and i have a
dispose function like this

protected override void Dispose(bool Disposing)
{
if (Disposing)
{
if (components != null)
{
components.Dispose();
}
}
Process[] procuo = Process.GetProcesses();
for (int i = 0; i < procuo.Length; i++)
{

if(procuo[i].ProcessName.Equals("client"))
{
procuo[i].Kill();
}
}

base.Dispose(true);

}
if i close the program normally(pressing X before it become invisible)
its normally closing the client.exe but if i kill it from task manager
its not closing the client.exe how can i do that?
Thanks
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 16 '05 #2

P: n/a
Dakkar,

you can try to override OnClose() and do the process killing there. But I am
not quite sure if anything gets fired once you killed a process. Another
way - which should work - is that you try to catch ThreadAbortException in
the Main() method running the Form. This should look something like this

public class MyForm : System.Windows.Forms.Form
{
// [...]

[STAThread]
static void Main()
{
try
{
Application.Run(new MyForm());
}
catch (ThreadAbortException e)
{
// kill process
}
}
}

Regards,
Michael

"Dakkar" <da****@sylveria.gen-dot-tr.no-spam.invalid> schrieb im Newsbeitrag
news:42********@127.0.0.1...
I have a program with windows forms and after execution of my program
im making it invisible for working background progress and i have a
dispose function like this

protected override void Dispose(bool Disposing)
{
if (Disposing)
{
if (components != null)
{
components.Dispose();
}
}
Process[] procuo = Process.GetProcesses();
for (int i = 0; i < procuo.Length; i++)
{

if(procuo[i].ProcessName.Equals("client"))
{
procuo[i].Kill();
}
}

base.Dispose(true);

}
if i close the program normally(pressing X before it become invisible)
its normally closing the client.exe but if i kill it from task manager
its not closing the client.exe how can i do that?
Thanks
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 16 '05 #3

P: n/a
any idea that how can i prevent this or if i cant prevent it how can i
make my process invisible(not show in task manager)
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 16 '05 #4

P: n/a
you can create a Windows Service or a Console Application that will not show
up in the task list.
"Dakkar" <da****@sylveria.gen-dot-tr.no-spam.invalid> wrote in message
news:42********@127.0.0.1...
any idea that how can i prevent this or if i cant prevent it how can i
make my process invisible(not show in task manager)
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.