Click here to Skip to main content
15,898,373 members
Home / Discussions / C#
   

C#

 
GeneralRe: Centering a window at runtime? Pin
James T. Johnson21-Sep-02 15:50
James T. Johnson21-Sep-02 15:50 
GeneralRe: Centering a window at runtime? Pin
Zinj22-Sep-02 4:51
sussZinj22-Sep-02 4:51 
GeneralRGB and HSV Pin
Tomas Petricek21-Sep-02 4:43
Tomas Petricek21-Sep-02 4:43 
GeneralRe: RGB and HSV Pin
leppie21-Sep-02 5:34
leppie21-Sep-02 5:34 
GeneralRe: RGB and HSV Pin
Stephane Rodriguez.21-Sep-02 5:42
Stephane Rodriguez.21-Sep-02 5:42 
GeneralRe: RGB and HSV Pin
leppie21-Sep-02 5:55
leppie21-Sep-02 5:55 
GeneralRe: RGB and HSV Pin
Tomas Petricek21-Sep-02 6:19
Tomas Petricek21-Sep-02 6:19 
GeneralScrolling Metrics Pin
leppie21-Sep-02 3:53
leppie21-Sep-02 3:53 
GeneralMulticolored Text Pin
Stickman21-Sep-02 1:38
Stickman21-Sep-02 1:38 
GeneralRe: Multicolored Text Pin
leppie21-Sep-02 1:51
leppie21-Sep-02 1:51 
GeneralRe: Multicolored Text Pin
Philip Fitzsimons23-Sep-02 7:14
Philip Fitzsimons23-Sep-02 7:14 
Questionhelp ( form message releted )? Pin
imran_rafique20-Sep-02 15:59
imran_rafique20-Sep-02 15:59 
AnswerRe: help ( form message releted )? Pin
James T. Johnson20-Sep-02 16:37
James T. Johnson20-Sep-02 16:37 
Questioncan any body help (releated to hook )? Pin
imran_rafique20-Sep-02 15:03
imran_rafique20-Sep-02 15:03 
Generalsocket timeout Pin
Rüpel20-Sep-02 3:27
Rüpel20-Sep-02 3:27 
GeneralRe: socket timeout Pin
Luis Alonso Ramos20-Sep-02 4:37
Luis Alonso Ramos20-Sep-02 4:37 
GeneralRe: socket timeout Pin
Rüpel22-Sep-02 22:23
Rüpel22-Sep-02 22:23 
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

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.