Answer the question
In order to leave comments, you need to log in
Socket breaks the connection when moving the mouse, how to solve?
Hello! There is such code (WPF project):
public partial class MainWindow : Window
{
IPAddress iP;
int port = 8005;
public MainWindow()
{
InitializeComponent();
}
private void EnterIP_Click(object sender, RoutedEventArgs e)
{
iP = IPAddress.Parse(IPAddressB.Text);
ConnectToServer();
}
void ConnectToServer()
{
new Thread(() => {
try
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(new IPEndPoint(iP, port));
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
MessageBox.Show(ex.Message);
}
}).Start();
}
}
Answer the question
In order to leave comments, you need to log in
It is in this version that the flow ends immediately after the connection. What happens to the object (Socket) the reference to which is lost? It becomes garbage and is destroyed when the garbage collector deigns to run. In your case, it is triggered by actions with WPF.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question