Killing the c# executable

  • Thread starter Thread starter Dakkar
  • Start date Start date
D

Dakkar

How can i control my program when someone kill it's process from the
taskmanager
my dispose script is working well if i close the program manually but
if i kill it from taskmanager its not working
how can i fix it
my dispose script is 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.ProcessName.Equals("client"))
{
procuo.Kill();
}
}

base.Dispose(true);

}
 
Dakkar,

What are you trying to achieve by doing this?

If you close your program from the task manager, it kills the process,
much like calling Kill on the Process class. This forces abnormal process
termination, just clearing the process out. It doesn't send a message to
the app to shut down, it just stops it, immediately.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Dakkar said:
How can i control my program when someone kill it's process from the
taskmanager
my dispose script is working well if i close the program manually but
if i kill it from taskmanager its not working
how can i fix it
my dispose script is 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.ProcessName.Equals("client"))
{
procuo.Kill();
}
}

base.Dispose(true);

}
 
Killing a process is just that, it doesn't allow the process to run any
longer. So I don't believe you can get your destroy to run if someone kills
the process. What you can try however, is maybe move the code below into a
service that runs as the system, or launch the application that runs the
code below as a different user.

--
Thanks
Wayne Sepega
Jacksonville, Fl


"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

Dakkar said:
How can i control my program when someone kill it's process from the
taskmanager
my dispose script is working well if i close the program manually but
if i kill it from taskmanager its not working
how can i fix it
my dispose script is 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.ProcessName.Equals("client"))
{
procuo.Kill();
}
}

base.Dispose(true);

}
 
Make it a service. Then the OS makes sure that you're notifed when someone
wants to shut you down.

Dakkar said:
so if i cant do something like this are there anyway to make my
process invisible
 
So how can i make my program as a service
Sean Hedermanwrote:
Make it a service. Then the OS makes sure that you're notifed when
someone
wants to shut you down.

so if i cant do something like this are there anyway to make my
process invisible


[/quote:2361bec79e]
 
File new Project --> Windows Service

I would suggest however, that you do some research on services first. Try
www.codeproject.com or the MDSN help file.

--
Thanks
Wayne Sepega
Jacksonville, Fl


"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

Dakkar said:
So how can i make my program as a service
Sean Hedermanwrote:
Make it a service. Then the OS makes sure that you're notifed when
someone
 
Back
Top