Home All Groups Group Topic Archive Search About

Running a process in a thread?

Author
26 Apr 2006 12:26 PM
Tyron
Is there a possibility to run an external process (exe) in on of my C#
Apps Thread?
I would need that because I don't want them to run anymore when my
programm crashes. Also I don't want to have the processes visible in
the task manager.

Author
26 Apr 2006 12:45 PM
Ignacio Machin ( .NET/ C# MVP )
Hi,


if you create a new process it will be, well , a new process :)

what you can do is terminate the process ( Process.Kill ) when your program
ends, for this you need to hook AppDomain.DomainUnload


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Show quoteHide quote
"Tyron" <tyron.madle***@kath-kirche-vorarlberg.at> wrote in message
news:1146054378.691597.209460@t31g2000cwb.googlegroups.com...
> Is there a possibility to run an external process (exe) in on of my C#
> Apps Thread?
> I would need that because I don't want them to run anymore when my
> programm crashes. Also I don't want to have the processes visible in
> the task manager.
>
Are all your drivers up to date? click for free checkup

Author
26 Apr 2006 12:47 PM
Jon Skeet [C# MVP]
Tyron wrote:
> Is there a possibility to run an external process (exe) in on of my C#
> Apps Thread?

Yes, but it won't help you.

> I would need that because I don't want them to run anymore when my
> programm crashes.

You'd have to manually kill the process when you detect a crash.

> Also I don't want to have the processes visible in the task manager.

If it's a separate process, it would be visible in task manager.

Now, if it's another .NET app you could load it in a different
AppDomain and call the Main method appropriately. Heck, you could
probably do that with non-.NET executables with a lot of work. I
wouldn't expect it to be particularly reliable though.

Jon
Author
26 Apr 2006 3:24 PM
Willy Denoyette [MVP]
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:1146055658.322123.296830@i39g2000cwa.googlegroups.com...
| Tyron wrote:
| > Is there a possibility to run an external process (exe) in on of my C#
| > Apps Thread?
|
| Yes, but it won't help you.
|
No, you can't run a process in a thread, what makes you believe you can do
this?


Willy.
Author
26 Apr 2006 5:06 PM
Jon Skeet [C# MVP]
Willy Denoyette [MVP] <willy.denoye***@telenet.be> wrote:
> | > Is there a possibility to run an external process (exe) in on of my C#
> | > Apps Thread?
> |
> | Yes, but it won't help you.

> No, you can't run a process in a thread, what makes you believe you can do
> this?

I initially misinterpreted the question. It's certainly possible to
create a new thread, and launch the process from that - but it will
indeed run on its own threads and be a completely distinct process.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Author
26 Apr 2006 12:58 PM
Kevin Spencer
Running a process from a thread is not going to change anything. the process
is started by your app, and the process must either stop by itself or be
stopped by an external force. A separte thread is only a child thread of
your main thread. What you need to do is ensure that if your app "crashes"
it stops the process before exiting.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

Show quoteHide quote
"Tyron" <tyron.madle***@kath-kirche-vorarlberg.at> wrote in message
news:1146054378.691597.209460@t31g2000cwb.googlegroups.com...
> Is there a possibility to run an external process (exe) in on of my C#
> Apps Thread?
> I would need that because I don't want them to run anymore when my
> programm crashes. Also I don't want to have the processes visible in
> the task manager.
>
Author
26 Apr 2006 2:45 PM
Stoitcho Goutsev (100)
Tyron,

I think you are not clear how processes and threads are related to each
other.

The process has threads. You cannot run a process IN a thread. You can
create a thread that starts a process, but this process will be different
entity and will have its own threads.

If the program you want to run is a managed .NET program you can run it in a
new application domain in the same Windows process.


--

Stoitcho Goutsev (100)


Show quoteHide quote
"Tyron" <tyron.madle***@kath-kirche-vorarlberg.at> wrote in message
news:1146054378.691597.209460@t31g2000cwb.googlegroups.com...
> Is there a possibility to run an external process (exe) in on of my C#
> Apps Thread?
> I would need that because I don't want them to run anymore when my
> programm crashes. Also I don't want to have the processes visible in
> the task manager.
>
Author
26 Apr 2006 2:54 PM
Tyron
Thanks a lot for all your answers.

The process I want to run is not a .net assembly but rather a linux
tool ported to windows called wget (I guess most of you know it).
I guess, since wget is open source, I maybe could recode some parts of
it so that I can compile it as a dll and do some PInvoke. On this way
it should be possible to run a "wget-process" in a thread.

Cheers
Author
26 Apr 2006 3:11 PM
Jon Skeet [C# MVP]
Tyron wrote:
> The process I want to run is not a .net assembly but rather a linux
> tool ported to windows called wget (I guess most of you know it).
> I guess, since wget is open source, I maybe could recode some parts of
> it so that I can compile it as a dll and do some PInvoke. On this way
> it should be possible to run a "wget-process" in a thread.

What functionality of wget do you particularly need? A lot of it is
already in the framework in the form of WebClient, HttpWebRequest etc.

Jon
Author
28 Apr 2006 8:40 AM
Tyron
I need all of them ;)
I've written a GUI for it (MyWebGet, http://www.tyron.at/tm/dev.php in
case you're interested) and I am curious if I can embedd wget even
better into the GUI
Author
26 Apr 2006 3:43 PM
Ignacio Machin ( .NET/ C# MVP )
Hi,

Of course we know wget :)

You need not to modify it, you can run it as a non-visible program (it will
shows n the windows task manager though) it will not appear in the task
toolbar nor using ALT+TAB .
You could even get the outout of the console and show it in your win app.


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Show quoteHide quote
"Tyron" <tyron.madle***@kath-kirche-vorarlberg.at> wrote in message
news:1146063270.196079.324530@e56g2000cwe.googlegroups.com...
> Thanks a lot for all your answers.
>
> The process I want to run is not a .net assembly but rather a linux
> tool ported to windows called wget (I guess most of you know it).
> I guess, since wget is open source, I maybe could recode some parts of
> it so that I can compile it as a dll and do some PInvoke. On this way
> it should be possible to run a "wget-process" in a thread.
>
> Cheers
>
Author
28 Apr 2006 8:44 AM
Tyron
Yep, I know. I already did that. I would be just somewhat nicer when
wget would run in a single thread instead of a seperate process.

Thanks tough for answering.

Bookmark and Share