Hey jeg har været igang med et project.
Jeg har lavet en ChatServer og vil gerne have et program til at holde det i live, altså sådan når eller hvis programmet crasher så starter den et nyt op. Jeg kan bare ikke rigtig få det til at virke.
Imports System.Net.Sockets
Imports System.Text
Public Class Form1
Dim clientSocket As New System.Net.Sockets.TcpClient()
Dim KeepOn As Boolean = Nothing
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
KeepOn = True
Timer1.Start()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
KeepOn = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If KeepOn = True Then
Try
If clientSocket.Connected = False Then
clientSocket.Connect("127.0.0.1", 5222)
End If
Label2.ForeColor = Color.Green
Label2.Text = "Online"
Catch ex As Exception
Label2.ForeColor = Color.Red
Label2.Text = "Offline"
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("ChatServer.exe")
For Each p As Process In pProcess
p.Kill()
Next
System.Diagnostics.Process.Start("C:\Documents and Settings\Qvintus\Skrivebord\VB\EL\ChatServer\ChatServer\bin\Release\ChatServer.exe")
End Try
ElseIf clientSocket.Connected = True Then
KeepOn = False
ElseIf clientSocket.Connected = False Then
KeepOn = True
End If
End Sub
End Class
Problem: Ja problemet er så at når den har startet programmet op, eller hvis programmet allerede er åbent så stopper den bare med at checke efter programmet.
PS. Bruger VB 2008
Indlæg senest redigeret d. 06.11.2009 19:53 af Bruger #15426