Hello
I have this problem where my windows.form doesnt quit when user logoff or system shutdown. It hangs the logoff/shutdown process witch is impossible to accept in a school.
The form is always active in background and hidden until an connection is made and then shows the form and hides it on a button click. (not visible in taskbar, but in systray)
The process hangs becouse of tcpListener.Stop() in sub popupmessage_FormClosing, that i have figured out.
Anyone know how to solve this?
My code:
I have this problem where my windows.form doesnt quit when user logoff or system shutdown. It hangs the logoff/shutdown process witch is impossible to accept in a school.
The form is always active in background and hidden until an connection is made and then shows the form and hides it on a button click. (not visible in taskbar, but in systray)
The process hangs becouse of tcpListener.Stop() in sub popupmessage_FormClosing, that i have figured out.
Anyone know how to solve this?
My code:
VB.NET:
Const portNumber As Integer = 2516
Dim tcpListener As New TcpListener(portNumber)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Visible = False
conn()
End Sub
Sub disconn()
Me.Visible = False
Me.tcpListener.Stop()
conn()
End Sub
Sub conn()
Me.tcpListener.Start()
'Console.WriteLine("Waiting for connection...")
Try
Me.tcpListener.AcceptTcpClient()
Me.Visible = True
Me.Show()
Me.Focus()
Catch er As Exception
tcpListener.Stop()
End Try
End Sub
Private Sub popupmessage_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If e.CloseReason = CloseReason.WindowsShutDown Then
Me.tcpListener.Stop() '[COLOR="Red"] Here is it the code freezes, Why ? oh Why?[/COLOR]
e.Cancel = False
End If
End If
End Sub