W
Water Cooler v2
I have a Windows Service I am writing in C# and a set of, let us say
three, other executables written in C# (mostly console applications).
I want that the Windows Service must do so every few seconds:
Check to see if each of the other executables are running or not. If
they are not running, it should load them.
For this purpose, I am planning the following:
I'll take a timer object and set it to an appropriate interval. In the
timer's timer/elapsed event, I will check if the other executables are
running or not. For checking that, I can use either of the following
approaches:
1. Use OpenProcess/CreateProcess with LP_SECURITY_ATTRIBUTES set to
NULL and with PROCESS_INFO. This will give me everything I need to
know, like, the threadID, the processID, in order to determine if the
process is running or not. The processID will be constant throughout
the life of each process. This will help me check if a process is
running or not.
2. ShellExecute/ShellExecuteEx - I am not sure if this is the right
approach. If I am assuming correctly, ShellExecuteEx only sets
GetLastError and returns a bool/int indicating success or failure. This
may not be the approach I might want to take as this will not give me
any information as to the status of the executable I have launched.
Besides, even semantically, this method might not be suited for the
purpose I have at hand, which is not to "launch documents in their
associated application."
3. Create a new app domain for each process I want to launch, add all
the appDomains to the same process, call ExecuteAssembly the
Application Domain for each executable I want to launch.
However, with the third approach, my knowledge of application domains
is still limited. I have a couple of questions in this regard.
a. Given that all this checking will be performed by a Windows Service,
which is not really a Win32 process, like ordinary Windows PE files or
executables, whether managed or unmanaged, what are the implications of
creating appdomains from within a Windows service? Is it an alright
thing to do to launch other Win32 processes from within a Windows
service?
b. Would it be possible for me to monitor the lifetime of an executable
which I execute inside an application domain? Remember that my main
purpose is to monitor in a timer if an application is running or not,
and if not, to launch it again.
c. What is the difference between System.AppDomain.Load() and
System.AppDomain.ExecuteAssembly()? Sorry, I am being lazy here, but it
is easier to ask a forum. I'm on my way to the MSDN, anyway. But kindly
oblige.
Thanks very much for your thoughts.
three, other executables written in C# (mostly console applications).
I want that the Windows Service must do so every few seconds:
Check to see if each of the other executables are running or not. If
they are not running, it should load them.
For this purpose, I am planning the following:
I'll take a timer object and set it to an appropriate interval. In the
timer's timer/elapsed event, I will check if the other executables are
running or not. For checking that, I can use either of the following
approaches:
1. Use OpenProcess/CreateProcess with LP_SECURITY_ATTRIBUTES set to
NULL and with PROCESS_INFO. This will give me everything I need to
know, like, the threadID, the processID, in order to determine if the
process is running or not. The processID will be constant throughout
the life of each process. This will help me check if a process is
running or not.
2. ShellExecute/ShellExecuteEx - I am not sure if this is the right
approach. If I am assuming correctly, ShellExecuteEx only sets
GetLastError and returns a bool/int indicating success or failure. This
may not be the approach I might want to take as this will not give me
any information as to the status of the executable I have launched.
Besides, even semantically, this method might not be suited for the
purpose I have at hand, which is not to "launch documents in their
associated application."
3. Create a new app domain for each process I want to launch, add all
the appDomains to the same process, call ExecuteAssembly the
Application Domain for each executable I want to launch.
However, with the third approach, my knowledge of application domains
is still limited. I have a couple of questions in this regard.
a. Given that all this checking will be performed by a Windows Service,
which is not really a Win32 process, like ordinary Windows PE files or
executables, whether managed or unmanaged, what are the implications of
creating appdomains from within a Windows service? Is it an alright
thing to do to launch other Win32 processes from within a Windows
service?
b. Would it be possible for me to monitor the lifetime of an executable
which I execute inside an application domain? Remember that my main
purpose is to monitor in a timer if an application is running or not,
and if not, to launch it again.
c. What is the difference between System.AppDomain.Load() and
System.AppDomain.ExecuteAssembly()? Sorry, I am being lazy here, but it
is easier to ask a forum. I'm on my way to the MSDN, anyway. But kindly
oblige.
Thanks very much for your thoughts.