i am creating a program that can wait for computer to connect in my server this code is initially implemented in console, but i want it in GUI form
MsgBox("Server is ready!", MsgBoxStyle.Information, "ChatApp! | Alert")
server = New TcpListener(ipendpoint)
server.Start()
While True
client = server.AcceptTcpClient
Dim c As New Connection
c.stream = client.GetStream
c.streamr = New StreamReader(c.stream)
c.streamw = New StreamWriter(c.stream)
c.hostname = c.streamr.ReadLine
list.Add(c)
FlatListBox1.AddItem(c.hostname)
ListView1.Items.Add(c.hostname & " is connected")
Dim t As New Threading.Thread(AddressOf ListenToConnection)
t.Start(c)
End While
Me.Show()
after adding this to the Form_load but my form is not clickable or else please help me this code work in background while my form is running
EDIT
I found an answer somewhere in google.
' Background work
Task.Factory.StartNew(Function()
' Update UI thread
End Function).ContinueWith(Function(t)
End Function, TaskScheduler.FromCurrentSynchronizationContext())
but I dont know how to merge it to my codes
i got an error after adding this
If Me.InvokeRequired Then
Me.BeginInvoke(Sub() TextBox1.Text = "Done")
End If