Form won't load

L

Lespaul36

I need a form to load on connection to a soket, but it hits the show and
does nothing..doesn't crash, just hangs.

Here is the code for the TCPListerner that I have set up.

Private Sub DoListen()

SocketChatS = New TcpListener(IPAddress.Any, MYPORT)

SocketChatS.Start()



Do

Dim x As New Client(SocketChatS.AcceptTcpClient)

Dim pobjForm As New frmServerChatUI

pobjForm.Client = x

pobjForm.Show()

mcolClients.Add(x.ID, x)





Loop Until False

End Sub
 
G

Guest

Hi

Your code seems to loop until something is set to false, but what? There is
nothing in that loop that is being tested for True/False so, it will continue
to loop, won't it? Example:

Public Sub DoSomething()

Do

Console.WriteLine("Hello World")

Loop Until False

End Sub

Where is the code to check validation is either true or false. It doesn't
exist
 
A

Adam Goossens

Hi Lespaul36,

Do you have any handlers attached to the Form.Open event? If so, you
might want to check them to see if they're causing the application to
hang. If you perform any blocking operations on the TcpClient you pass
to pobjForm while you're in the Open handlers, you will appear to "hang"
the application.

If that is a problem, you might try Asynchronous sockets instead.

Regards,
-Adam.
 
L

Lespaul36

I have tried many things. I still have not found anything that seems to
work. Here is the portions of my code that deal with the socket maybe you
have a better idea? The form still seems to hang. I got it to not hang if
I used a loop with a application.doevents, but it was not CPU friendly.

'Declarations
Private SocketChatS As Socket
Private SocketChatC As TcpClient
Private marrClients As New ArrayList
Private allDone As New System.Threading.ManualResetEvent(True)



Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
If Not designmode Then
Dim ipAdd() As System.Net.IPAddress =
System.Net.Dns.Resolve("localhost").AddressList
mthrListen = New System.Threading.Thread(AddressOf DoListen)
mthrListen.Start()
End If
End Sub

Private Sub DoListen()
Dim Iphe As IPHostEntry = Dns.Resolve(Dns.GetHostName)
Dim Ipep As New IPEndPoint(IPAddress.Any, MYPORT)
SocketChatS = New Socket(Ipep.Address.AddressFamily, SocketType.Stream,
ProtocolType.Tcp)
Dim blnFirst As Boolean = True
Dim pobjFRM As frmServerChatUI

With SocketChatS
.Blocking = False
.Bind(Ipep)
.Listen(100)
End With

While True
allDone.Reset()
SocketChatS.BeginAccept(New AsyncCallback(AddressOf AcceptClient),
SocketChatS)
allDone.WaitOne()
End While

End Sub

Private Sub AcceptClient(ByVal ar As IAsyncResult)
allDone.Set()

Dim pobjFRM As New frmServerChatUI
pobjFRM.Show()

Dim pintIndex As Integer = marrClients.Add(New HabibSocket.HabibsSocket)
marrClients(pintIndex).tcpsocket = SocketChatS.EndAccept(ar)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top