c# - Client Server freezing interface -


i have problems client/server project. don't know why client interface freezes text changing cannot press button. code of client is:

    private void connect_click(object sender, eventargs e)     {         try         {             // create 1 socketpermission socket access restrictions              socketpermission permission = new socketpermission(                 networkaccess.connect,    // connection permission                  transporttype.tcp,        // defines transport types                  "",                       // gets ip addresses                  socketpermission.allports // ports                  );              // ensures code have permission access socket              permission.demand();              // resolves host name iphostentry instance                         ipaddress[] ipaddress = dns.gethostaddresses("127.0.0.1");              // gets first ip address associated localhost              ipaddress ipaddr = ipaddress[0];             console.writeline("------>" + ipaddr.tostring());             // creates network endpoint              ipendpoint ipendpoint = new ipendpoint(ipaddr, 54000);              // create 1 socket object setup tcp connection              sendersock = new socket(                 ipaddr.addressfamily,// specifies addressing scheme                  sockettype.stream,   // type of socket                   protocoltype.tcp     // specifies protocols                   );              sendersock.nodelay = false;   // using nagle algorithm               // establishes connection remote host              sendersock.connect(ipendpoint);              connect.enabled = false;              thread tid = new thread(new threadstart(threadlistening));             tid.start();          }         catch (exception exc)         {             messagebox.show(exc.tostring());         }     }      private void threadlistening()     {         while (true)         {             this.invoke((methodinvoker)delegate ()             {                 int bytesrec = sendersock.receive(bytes);                  // converts byte array string                  string themessagetoreceive = encoding.utf8.getstring(bytes, 0, bytesrec);                  // continues read data till data isn't available                  while (sendersock.available > 0)                 {                     bytesrec = sendersock.receive(bytes);                     themessagetoreceive += encoding.utf8.getstring(bytes, 0, bytesrec);                 }                  txt.text = "the server reply: " + themessagetoreceive;             });             thread.sleep(1000);         }     } 

i can receive arrives server cannot move interface or close program. can me?


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -