c# - socket.connect() freezes windows -
i have code tries establish connection every 3 seconds using tcp , blocking socket. whenever tries establish connection socket.connect(), windows applications freeze moment, can't type in notepad. have tested on 2 pcs same result. codes resides in timer event.
how avoid freezing without using asynchronous methods?
code:
ipendpoint remoteep = new ipendpoint(ip, mainport); // create tcp/ip socket. commandreceiversocket = new socket(addressfamily.internetwork, sockettype.stream, protocoltype.tcp); commandreceiversocket.setsocketoption(socketoptionlevel.socket, socketoptionname.keepalive, 0); commandreceiversocket.blocking = true; commandreceiversocket.connect(remoteep);
trying establish connection within ui thread in language can cause this. not healthy @ call within loop or timer in form of application.
try run related connection in different thread , don't use ui thread.
Comments
Post a Comment