Question windows forms sockets and run time error

MTester

Member
Joined
Mar 18, 2011
Messages
5
Programming Experience
Beginner
I wrote a windows application with sockets. I am having a weird problem with my app. When I try to close the application gives me exe has encountered a problem and needs to close. We are sorry for the inconvenience. I was not able to catch the error. Please some one help to catch /find out that error. I used try catch and also write to event view and no luck.
 
There's no way we can tell you what the problem is based on the fact that you're using a Socket and you get an error. You could start by showing us what you're doing with that Socket. Also, does that error message appear when debugging? Is there any option to view details?
 
I wrote the same program in c# sharp and works fine. When I try to do it in vb.net gives that error. Basically my application is sockets server app. I used little bit of threading with sockets. It just takes ip address and port of the client machine. I don't know it could be how the c# sharp handles threading and vb.net threading. I have the below code in form_activated event.

If clientConnectionsSocket Is Nothing Then
' Get server's details based on the name specified in DNS
Dim serverIPEntry As IPHostEntry = Dns.GetHostEntry(Dns.GetHostName())
' Get IP Address and assign it to the IP Address text box
TextBox1.Text = serverIPEntry.AddressList(0).ToString()
If IPAddress.TryParse(TextBox1.Text, validIPAddress) Then
' Create new socket to accept client connections
clientConnectionsSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
'clientConnectionsSocket.Bind(New IPEndPoint(validIPAddress, Integer.Parse(glngBatchTcpPort)))
clientConnectionsSocket.Bind(New IPEndPoint(validIPAddress, 15001))
clientConnectionsSocket.Listen(MAX_CONNECTIONS)
clientConnectionsSocket.BeginAccept(
New AsyncCallback(AddressOf ExecuteMeWhenAccepted), clientConnectionsSocket)
End If
End If
 
I couldn't view the details of the error. As I used try.. catch to catch the error and I was unsuccessful. I was trying to write to event viewer to findout the details of the error and no luck. Is anyone have any other suggesions and advices.
 
Try adding an application-level UnhandledException event handler. This should be guaranteed successful to catch all errors...You would be unable to catch the error in a try/catch block if it is thrown on a separate thread.

Catch and handle all unhandled exceptions in your VB.NET program with Application Domains

That's the complicated way to do it. Assuming that the Application Framework is enabled in your project, which it is by default, you can click the View Events button on the Application page of the project properties and then use the drop-downs at the top of the code file to create a handler for the UnhandledException event of the application.
 
I have tried your suggestions before I posted a question, and no luck.
Whose suggestion? Two of us posted. Did you try them both? If they didn't work then you may well have done it wrong, so maybe you should show us what you tried.
 
Back
Top