473,320 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Disposing Question

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
4 2213
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Chris Capel | last post by:
I've heard a lot of talk on the forum about memory managment in .NET and disposing things, finalizing them, garbage collection, etc. My question is which managed types need to be disposed after...
10
by: Patrick De Ridder | last post by:
I have been looking at an example, and there is something I don't inderstand. Given: form1 calls form2 --------- Question: What is the use of having these lines in form2 --------------...
4
by: MC D | last post by:
Question: If I have a class which has a property which is a collection of widget objects (an arrayList of widgets), and both the containter class and the widget class implement the IDisposable...
5
by: Mathias L. | last post by:
I have two questions for which I couldnt find answer: If I programaticaly close DialogForm (calling Close()), is it enough or do I have to dispose it as MS.NET help says? Also, in overriden...
13
by: MuZZy | last post by:
Hi, Just wanted to make sure i get it right: consider this class: // =========== START CODE ============= class Test { private SqlConnection con = null; public void Connect() { con = new...
5
by: keithv | last post by:
I came across the following code snippet in a project I inherited. Having 2 close() and 2 dispose() calls for essentially one stream seems to me to be way too much overkill. What is the proper...
0
by: Gman | last post by:
Hi, Objective: Draw a grid on a bitmap and set this as a panel's image. (Rather than draw the grid directly on the panel and redraw repeatedly in the paint event.) Problem: It works fine....
8
by: Varangian | last post by:
Hello, was wondering of how to dispose of managed resources? or referencing every member of a class to null will release resources...? http://www.marcclifton.com/tabid/79/Default.aspx...
29
by: Jerry Spence1 | last post by:
I'm rather confused as to whether something should be disposed of, or not. What is the general rule? How can you be sure of doing the right thing? I've heard about disposing unmanaged resources but...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.