Stop Thread

  • Thread starter Thread starter Osvaldo Bisignano
  • Start date Start date
O

Osvaldo Bisignano

When I press a button, I start a new Exe file as a new Thread.
When the mainform of that exe closes, i thought the thread was over.

When and How shoud i terminate the subprocess?
 
Osvaldo,

When you create a new EXE to run, it does not run in a new thread.
Rather, it runs in a new process. When the EXE is done executing, the
process is done, not the thread that created the new process.

Hope this helps.


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

When I press a button, I start a new Exe file as a new Thread.
When the mainform of that exe closes, i thought the thread was over.

When and How shoud i terminate the subprocess?
 
When I press a button, I start a new Exe file as a new Thread.

could you, please, send actual code from your application?
exes are never run as threads - they are run as processes. why do you need
the thread then?

Regards, Wiktor
 
Hi Osvaldo,
How do you start that exe?
IMHO the exe should be started in new application domain. Which means that you have two separate applications running. So, closing one of them doesn't have to affect the other one. Anyway, you can use AppDomain.Unload methods if you want to unload a domain. This will cause Thread.Abort to be called in any of the threads in the app domain to be unloaded. But this IMHO is not a polite way to stop a program.

If you have control on how that exe is written you can provide nicer way to stopping it.

B\rgds
100

When I press a button, I start a new Exe file as a new Thread.
When the mainform of that exe closes, i thought the thread was over.

When and How shoud i terminate the subprocess?
 
Here's the code. I had lost this message and today I found it again.

I use this to call an executable file and load it in the same AppDomain than the caller. I know it loads it in a "subprocess". I need to get access or "Enumerate" these subproceses and ask the subprocess to exit normally (among other common tasks such as maximize, etc)

I need all the files to load in the same AppDomain cause this allows me to have a shared object which -in a way- persists through all the subproceses. So I set a value to this shared object from ModuleA.exe and I can get/set that value in ModuleB.exe.

Private Sub btnTablas(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim t As Thread

t = New Thread(AddressOf AbrirTablas)

t.Name = "Modulo Tablas"

t.Start()

End Sub

Private Sub AbrirTablas()

Dim ad As AppDomain = AppDomain.CurrentDomain

ad.ExecuteAssembly("Legion.Tablas.exe")

End Sub

Thanks Guys

Osvaldo
 
Back
Top