PC Review


Reply
Thread Tools Rate Thread

Disposing Question

 
 
Dakkar
Guest
Posts: n/a
 
      14th Feb 2005
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
 
Reply With Quote
 
 
 
 
Sean Hederman
Guest
Posts: n/a
 
      14th Feb 2005
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" <(E-Mail Removed)> wrote in message
news:4210b064_3@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



 
Reply With Quote
 
Michael Groeger
Guest
Posts: n/a
 
      14th Feb 2005
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" <(E-Mail Removed)> schrieb im Newsbeitrag
news:4210b064_3@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



 
Reply With Quote
 
Dakkar
Guest
Posts: n/a
 
      18th Feb 2005
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
 
Reply With Quote
 
Pipo
Guest
Posts: n/a
 
      18th Feb 2005
you can create a Windows Service or a Console Application that will not show
up in the task list.


"Dakkar" <(E-Mail Removed)> wrote in message
news:42158640_4@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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disposing - when? TyBreaker Microsoft VB .NET 1 22nd Aug 2006 12:01 PM
question of disposing Mathias L. Microsoft C# .NET 5 20th Sep 2004 10:04 AM
Question on Disposing of Resources Joe Keller Microsoft Dot NET Compact Framework 5 10th May 2004 04:35 PM
disposing of oe santy Windows XP Internet Explorer 4 3rd Jan 2004 01:25 AM
Disposing question Patrick De Ridder Microsoft C# .NET 5 2nd Aug 2003 09:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:57 PM.