winforms - When debuging the window doesn't appear -


`using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.net.sockets; using system.net; using system.threading;  namespace server_chat {     class server     {         private static int myprot = 10000;         private static byte[] buf2 = new byte[1024];         private static socket serversocket;         private static string message2;          /// <summary>         /// server socket         /// </summary>         public void server_run()         {             iphostentry iphost = dns.resolve(dns.gethostname());             ipaddress ip = iphost.addresslist[0];              serversocket = new socket(addressfamily.internetwork, sockettype.stream, protocoltype.tcp);             serversocket.bind(new ipendpoint(ip,program.form1.localport));             serversocket.listen(10);             program.form1.myscan_box = "启动监听成功 !!";              thread mythread = new thread(listenclientconnect);             mythread.isbackground = true;             mythread.start();         }          /// <summary>           /// 监听客户端连接           /// </summary>           private static void listenclientconnect()         {             while (true)  // 点对点通信             {                 socket clientsocket = serversocket.accept();                 if (clientsocket.connected == true)                 {                     ipendpoint client_endpoint = (ipendpoint)clientsocket.remoteendpoint;                     program.form1.myclientip_box = client_endpoint.address.tostring() + "\\" + client_endpoint.port.tostring();                     program.form1.myscan_box = "连接客户端 " + client_endpoint.address.tostring() + " 成功 !!";                     //服务端接收线程                     thread receivethread = new thread(receivemessage);                     receivethread.isbackground = true;                     receivethread.start(clientsocket);                     //服务端发送线程                     thread sendthread = new thread(sendmessage);                     sendthread.isbackground = true;                     sendthread.start(clientsocket);                     break;                 }             }         }          /// <summary>           /// receive message          /// </summary>           /// <param name="clientsocket"></param>           private static void receivemessage(object clientsocket)         {             socket myclientsocket = (socket)clientsocket;             while (true)             {                 try                 {                     int len = myclientsocket.receive(buf2);                     message2 = encoding.ascii.getstring(buf2).substring(0, len);                     ipendpoint client_endpoint = (ipendpoint)myclientsocket.remoteendpoint;                     program.form1.myscan_box = client_endpoint.address +": "+ message2;                 }                 catch (exception ex)                 {                     program.form1.myscan_box = ex.message;                     myclientsocket.shutdown(socketshutdown.both);                     myclientsocket.close();                     break;                 }             }         }           /// <summary>         /// send message         /// </summary>         /// <param name="clientsocket"></param>         private static void sendmessage(object clientsocket)         {             socket myclientsocket = (socket)clientsocket;             while (true)             {                 if (program.form1.send_flag11 == 1)                 {                     myclientsocket.send(encoding.ascii.getbytes(program.form1.message11));                     program.form1.send_flag11 = 0;                 }             }          }      } } 

`when starting or debugging program window doesn't appear. vs2012 suggests debug session ready.

when startting program, window appears popup window message "the program has stopped working, choose debug or stop".

what's problem? should do?

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; using system.net; using system.threading;  namespace server_chat {     public partial class form1 : form     {         public string localip;         public int localport = 10002;         public string s_sendmessage;         public static int send_flag = 0;           public string message11         {             { return s_sendmessage; }         }         public int send_flag11         {             { return send_flag; }             set { send_flag = value; }         }          public form1()         {             initializecomponent();             control.checkforillegalcrossthreadcalls = false;             iphostentry iphost = dns.resolve(dns.gethostname());             ipaddress ipaddr = iphost.addresslist[0];             localip = ipaddr.tostring();              myip_box.text = localip;             port_box.text = localport.tostring();               server myserver = new server();             thread th_server = new thread(myserver.server_run);             th_server.isbackground = true;             th_server.start();         }          private void setting_btn_click(object sender, eventargs e)         {             localport = int16.parse(port_box.text);             scan_box.appendtext("\r\n" + "端口改成: " + port_box.text);         }          private void send_btn_click(object sender, eventargs e)         {             s_sendmessage = chat_box.text;             chat_box.text = "";             scan_box.appendtext(s_sendmessage + "\r\n");             send_flag = 1;         }      } } 


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -