Click here to Skip to main content
15,868,016 members
Home / Discussions / C#
   

C#

 
Generalthis is not solved yet Pin
Rüpel23-Sep-02 4:00
Rüpel23-Sep-02 4:00 
GeneralRe: socket timeout Pin
Daniel Turini23-Sep-02 9:16
Daniel Turini23-Sep-02 9:16 
GeneralRe: socket timeout Pin
Rüpel23-Sep-02 10:09
Rüpel23-Sep-02 10:09 
Generalstill doesn't work Pin
Rüpel23-Sep-02 20:52
Rüpel23-Sep-02 20:52 
Generalfinally Pin
Rüpel23-Sep-02 21:53
Rüpel23-Sep-02 21:53 
GeneralEiffel .NET for Visual Studio .NET Plug-in Pin
Kevin McFarlane20-Sep-02 1:50
Kevin McFarlane20-Sep-02 1:50 
GeneralBackground and foreground color for disabled state Pin
valos20-Sep-02 1:18
valos20-Sep-02 1:18 
QuestionShut down one program from another? Pin
Matt Philmon19-Sep-02 18:11
Matt Philmon19-Sep-02 18:11 
First of all, I'm cross posting this question from the VB.NET forum to hopefully get more replys. If you know the correct way to do this in C# then I can easily port that method over to VB.NET since they use the same namespaces and I'm equally comfortable in either language.

I have a VB.NET application that runs all the time in a custom Kiosk my company builds. I'd like to be able to shutdown and then restart our application remotely. We use Remote Administrator for this now, but there's a lot of them so when I have a need to do things like this I'd rather not do it manually. So, I wrote a Service that runs in our Kiosks. Since our units are equipped with an FTP server, my service simply looks for an XML file to show up in a certain directory. The XML file contains a list of "commands", one of which is to shut down our software. In looking in how to shut down another process I looked at the System.Diagnostics.Process namespace and wrote this:

from within "Main":
Dim ProcessHandler As New System.Diagnostics.Process()
If (FindRunner(ProcessHandler)) Then
ProcessPath = StopRunner(ProcessHandler)
End If

' Functions
Private Function StopRunner(ByVal Process As System.Diagnostics.Process) As String
Dim ProcessPath As String
ProcessPath = Process.MainModule.FileName
Process.CloseMainWindow()
Process.WaitForExit(3000)
If Not Process.HasExited Then
Process.Kill()
End If
Return ProcessPath
End Function

Private Function FindRunner(ByRef Process As System.Diagnostics.Process) As Boolean
Dim colProcess() As System.Diagnostics.Process
colProcess = Diagnostics.Process.GetProcessesByName("TEC_Runner")
If colProcess.Length > 0 Then
Process = colProcess(0)
Return True
End If
Return False
End Function


The Kill() was added later when I realized that CloseMainWindow() wasn't working for me from within the Service. Debugging a service is kind of a pain, so I first wrote the code as just another VB.NET application and this worked great every time. However, when I moved the same code into the Service, the WaitForExit() never returned (I didn't specify any milliseconds at first which of course meant it locked up). I don't understand why it works every time from within a normal application, but NEVER succeeds from within a Service. Do I need to do this some other way? Any ideas what's going on? Using Kill() works... mostly... but it rips the application down without letting it cleanup (and it does important things when being shut down normally that I need it to do). Please help!


Thanks!
Matt Philmon
AnswerRe: Shut down one program from another? Pin
Stephane Rodriguez.19-Sep-02 19:08
Stephane Rodriguez.19-Sep-02 19:08 
GeneralRe: Shut down one program from another? Pin
Matt Philmon19-Sep-02 20:50
Matt Philmon19-Sep-02 20:50 
GeneralRe: Shut down one program from another? Pin
Stephane Rodriguez.19-Sep-02 21:23
Stephane Rodriguez.19-Sep-02 21:23 
GeneralRe: Shut down one program from another? Pin
Matt Philmon20-Sep-02 4:47
Matt Philmon20-Sep-02 4:47 
GeneralRe: Shut down one program from another? Pin
leppie20-Sep-02 5:22
leppie20-Sep-02 5:22 
GeneralRe: Shut down one program from another? Pin
Matt Philmon20-Sep-02 21:33
Matt Philmon20-Sep-02 21:33 
GeneralRe: Shut down one program from another? Pin
Stephane Rodriguez.21-Sep-02 1:52
Stephane Rodriguez.21-Sep-02 1:52 
GeneralRe: Shut down one program from another? Pin
leppie21-Sep-02 2:01
leppie21-Sep-02 2:01 
GeneralRe: Shut down one program from another? Pin
Matt Philmon21-Sep-02 5:49
Matt Philmon21-Sep-02 5:49 
GeneralBeta of .NET Framework Version 1.1 now available Pin
Eric Gunnerson (msft)19-Sep-02 12:30
Eric Gunnerson (msft)19-Sep-02 12:30 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
David Stone19-Sep-02 13:11
sitebuilderDavid Stone19-Sep-02 13:11 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
Eric Gunnerson (msft)23-Sep-02 7:30
Eric Gunnerson (msft)23-Sep-02 7:30 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
Matt Philmon20-Sep-02 21:34
Matt Philmon20-Sep-02 21:34 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
James T. Johnson21-Sep-02 2:07
James T. Johnson21-Sep-02 2:07 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
leppie21-Sep-02 2:06
leppie21-Sep-02 2:06 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
David Stone21-Sep-02 5:26
sitebuilderDavid Stone21-Sep-02 5:26 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
leppie21-Sep-02 5:50
leppie21-Sep-02 5:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.