Themes, Processes, and Application.Exit ()

My application consists of a main message loop (GUI) and threads (Task.Factory).

In threads, I call some third-party applications with var p = new Process();

But when I call Application.Exit();in the message loop, I see that the processes that were running in the threads are still in memory and are executing.

So the question is: how to kill all threads and processes immediately after the call Application.Exit();?

UPD

old:

p.WaitForExit();

new

while (!p.WaitForExit(1000))
{
    if (FlagToExit)
    {
        p.Kill();
        return;
    }
}
+3
source share
6 answers

Just try this

when you create a thread do a background thread

Thread.IsBackground = true;

and on Application.Exit();

all thread will be closed

+8
source

.

, , .

, Process.CloseMainWindow Process.Kill, , .

+1

, Foreground. Foreground (GUI) Foreground. Background Foreground (GUI). Background, :

p.IsBackground = true;
+1

, .

0

Invoke() Application.Exit() :

this.Invoke((Action)delegate ()
{
    Application.Exit();
});
-1

Source: https://habr.com/ru/post/1764264/


All Articles