希望大哥们帮忙解决下

问题描述

程序移植到PDA上由于没有Form.CheckForIllegalCrossThreadCalls=false;所以一直报错Control.Invoke必须用于与在独立线程上创建的控件交互,代码不完全是自己写的,所以不是非常懂,我把代码贴上,希望大哥们能帮帮小弟解决下:usingSystem;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Collections;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Threading;namespacePDA1{publicdelegatevoidEventMsg(Sessionsession);publicpartialclassForm1:Form3{TcpClim_TcpCli=newTcpCli();stringm_strServerIp;intm_iPortNum;stringmyID="";publicForm1(){InitializeComponent();Form3.ht.Add("tb_sendmsg",this.tb_sendMsg);//Form.CheckForIllegalCrossThreadCalls=false;m_TcpCli.ReceivedDatagram+=newNetEvent(_Receive_Msg);m_TcpCli.ConnectedServer+=newNetEvent(_ConnectedServer);m_TcpCli.ConnectError+=newNetEvent(_ConnectError);m_TcpCli.SendError+=newNetEvent(m_TcpCli_SendError);m_TcpCli.DisConnectedServer+=newNetEvent(m_TcpCli_DisConnectedServer);}privatestringgetdatetime(){returnSystem.DateTime.Now.ToShortDateString()+""+System.DateTime.Now.ToLongTimeString();}publicstringgetid(){Randomrnd=newRandom();inti=rnd.Next(10,99);stringid=DateTime.Now.Year.ToString()+string.Format("{0:00}",Convert.ToInt16(DateTime.Now.Month.ToString()))+string.Format("{0:00}",Convert.ToInt16(DateTime.Now.Day.ToString()))+string.Format("{0:00}",Convert.ToInt16(DateTime.Now.Hour.ToString()))+string.Format("{0:00}",Convert.ToInt16(DateTime.Now.Minute.ToString()))+string.Format("{0:00}",Convert.ToInt16(DateTime.Now.Second.ToString()))+i.ToString();returnid;}privatevoidop_con(){bt_state.BackColor=Color.Green;this.lb_state.Text="已连接!";lb_SendCliName.Text="server";}privatevoidop_coning(){bt_state.BackColor=Color.Yellow;this.lb_state.Text="连接中。。。";}privatevoidop_cls(){bt_state.BackColor=Color.Gray;this.lsb_Clients.Items.Clear();//this.t_msg.Clear();lb_SendCliName.Text="";this.lb_state.Text="未连接!";myID="";}privatevoid_Receive_Msg(objectsender,NetEventArgse){this.BeginInvoke(newEventMsg(Proc_msg),newobject[]{e.Client});}privatevoidProc_msg(Sessionse){stringstrFromServer=se.Datagram;stringlb="",sendId="",msg="";string[]strClient=strFromServer.Split('|');lb=strClient[0];sendId=strClient[1];for(inti=2;i<strClient.Length;i++){if(i>2)msg+="|"+strClient[i];elsemsg+=strClient[i];}if(lb=="msg"){UpDataLst_msg(sendId,msg);}elseif(lb=="con"){lsb_Clients.Items.Clear();if(this.myID==""){myID=sendId;this.lb_state.Text+="用户名:"+sendId;}this.t_msg.Text+=this.getdatetime()+""+sendId+"用户已登录"+"rn";string[]strIds=msg.Split('|');for(inti=0;i<strIds.Length;i++){lsb_Clients.Items.Add(strIds[i]);}}elseif(lb=="cls"){lsb_Clients.Items.Clear();this.t_msg.Text+=this.getdatetime()+""+sendId+"用户已退出"+"rn";string[]strIds=msg.Split('|');for(inti=0;i<strIds.Length;i++){lsb_Clients.Items.Add(strIds[i]);}}elseif(lb=="err"){this.t_msg.Text+=this.getdatetime()+""+"系统提示:给"+sendId+"的消息发送失败!"+"rn";}else{MessageBox.Show("消息类别错误,已断开连接!");m_TcpCli.Close();this.op_cls();}}privatevoidUpDataLst_msg(stringid,stringstr){this.t_msg.Text+=this.getdatetime()+""+"来自"+id+"的消息:rn"+str+"rn";}privatevoid_ConnectedServer(objectsender,NetEventArgse){this.op_con();}privatevoid_ConnectError(objectsender,NetEventArgse){this.op_cls();}privatevoidm_TcpCli_SendError(objectsender,NetEventArgse){MessageBox.Show("SendErrorrn发送失败,请重新连接!");try{m_TcpCli.Close();}catch(Exceptionex){MessageBox.Show(ex.Message);}this.op_cls();}voidm_TcpCli_DisConnectedServer(objectsender,NetEventArgse){m_TcpCli.Close();this.op_cls();}privatevoidbt_Connect_Click(objectsender,EventArgse){if(m_TcpCli.IsConnected){MessageBox.Show("已经建立连接!");return;}m_strServerIp=tb_ServerIp.Text.ToString().Trim();m_iPortNum=int.Parse(tb_Port.Text.ToString().Trim());try{m_TcpCli.Connect(m_strServerIp,m_iPortNum);}catch(Exceptionexx){MessageBox.Show("连接服务器:"+m_strServerIp+"失败!"+exx.Message);return;}this.op_coning();this.label_con.Text="con";}privatevoidbt_Disconnect_Click(objectsender,EventArgse){try{m_TcpCli.Close();}catch(Exceptionex){MessageBox.Show(ex.Message);}this.op_cls();this.label_con.Text="";}privatevoidbt_Send_Click(objectsender,EventArgse){if(!m_TcpCli.IsConnected){MessageBox.Show("未连接到服务器,不能发送信息!");return;}if(lb_SendCliName.Text==""){MessageBox.Show("未选中客户端对象!");return;}if(this.myID==lb_SendCliName.Text){MessageBox.Show("不能给自己发信息!");return;}this.sendToServer(this.tb_sendMsg.Text.ToString());MessageBox.Show("信息已经发送!");this.t_msg.Text+=this.tb_sendMsg.Text;}privatevoidsendToServer(stringstr){m_TcpCli.Send(str);}privatevoidlsb_Clients_SelectedIndexChanged(objectsender,EventArgse){if(lsb_Clients.Items.Count<1)return;try{stringstr=lsb_Clients.SelectedItem.ToString();string[]strClient=str.Split('');lb_SendCliName.Text=strClient[0];}catch{}}privatevoidtimer1_Tick(objectsender,EventArgse){if(this.label_con.Text=="con"&&!m_TcpCli.IsConnected&&this.lb_state.Text=="未连接!"){try{m_TcpCli.Connect(m_strServerIp,m_iPortNum);}catch{return;}this.op_coning();}}privatevoidbutton1_Click(objectsender,EventArgse){this.lb_SendCliName.Text="server";this.tb_ServerIp.Text="10.0.6.93";this.tb_Port.Text="10008";stringa="数据清空";MessageBox.Show(a.Length.ToString());this.tb_sendMsg.Text=a;}privatevoidlb_SendCliName_Click(objectsender,EventArgse){}privatevoidlsb_Clients_SelectedIndexChanged_1(objectsender,EventArgse){}protectedvoid移库电文_LinkClicked(objectsender,EventArgse){Form2fm2=newForm2();fm2.Show();}//protectedvoid上料电文_LinkClicked(objectsender,EventArgse)//{//Form5fm3=newForm5();//fm3.Show();//}privatevoidForm1_Load(objectsender,EventArgse){}privatevoidt_msg_TextChanged(objectsender,EventArgse){}privatevoidbutton2_Click(objectsender,EventArgse){Form4fm1=newForm4();fm1.Show();}}}

解决方案

解决方案二:
顶起来,希望有人帮忙解决啊
解决方案三:
楼主发错版块了?纯支持。。
解决方案四:
该回复于2012-02-01 09:03:14被版主删除

时间: 2024-08-03 23:53:58

希望大哥们帮忙解决下的相关文章

运行时一直报这个错误,我是新手希望大神帮忙解决下,不胜感激

问题描述 解决方案 解决方案二:看代码是C#的吧?你在C#中调用了C++的库吗?解决方案三:程序运行缺少东西,具体自己看看那个dll没有被引用到.解决方案四:引用2楼duanzi_peng的回复: 程序运行缺少东西,具体自己看看那个dll没有被引用到. +1解决方案五:用Depends工具查看dll文件依赖关系,把缺少的文件引用进来解决方案六:点开引用那里,看看有没有黄色的感叹号

大神们,我遇到一个问题希望大神帮忙解决下,谢谢啦

问题描述 typeExceptionreportmessagedescriptionTheserverencounteredaninternalerror()thatpreventeditfromfulfillingthisrequest.exceptionjava.lang.reflect.InvocationTargetExceptionsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)sun.reflect.NativeMe

adb-[求救向] 请各位大神帮忙解决下吧,有关于安卓开发运行写好的项目的时候出现问题

问题描述 [求救向] 请各位大神帮忙解决下吧,有关于安卓开发运行写好的项目的时候出现问题 错误输出[2015-05-27 17:20:55 - Bluetooth] ------------------------------[2015-05-27 17:20:55 - Bluetooth] Android Launch![2015-05-27 17:20:55 - Bluetooth] The connection to adb is down and a severe error has o

linux网络编程-linux方面遇到的一个难题,希望大哥大姐帮忙解决下,小弟是菜鸟,刚学linux编程

问题描述 linux方面遇到的一个难题,希望大哥大姐帮忙解决下,小弟是菜鸟,刚学linux编程 /proc/进程号/statm包含了进程使用内存的信息,如[root@cs 9519]# more statm 18095 2094 1468 7 0 605 0 [root@cs 9519]# ps 9519PID TTY STAT TIME COMMAND9519 ? S 0:00 /usr/libexec/notification-daemonmore statm 18095 2094 1468

一个空指针异常问题,求大神帮忙解决下,在线等

问题描述 一个空指针异常问题,求大神帮忙解决下,在线等 public void getQaList(String type, String qid, String qid_min, String cat_id, String tag_id, String page, String qid_top, boolean isShowLoadingDialog) { List<RequestParameter> parameter = new ArrayList<RequestParameter

请哪位大神帮忙解决下这个问题-内存泄露

问题描述 请哪位大神帮忙解决下这个问题-内存泄露 请哪位大神帮忙解决下这个问题,实在是找不到哪个地方内存泄露,凡是代码中用到new的,我都delete了... Detected memory leaks! Dumping objects -> {107} normal block at 0x00206188, 21 bytes long. Data: < l| > A8 6C 7C 00 04 00 00 00 04 00 00 00 01 00 00 00 {106} normal b

求帮助-求大神帮忙解决下这个问题

问题描述 求大神帮忙解决下这个问题 Exception in thread "Thread-15" java.lang.NullPointerException at com.amtch.akka.slave.impl.SlaveServiceImpl.process(SlaveServiceImpl.java:51) at com.amtch.akka.communication.protocol.socket.SocketClient.run(SocketClient.java:5

php开发遇到错误 Creating default object from empty value 求大神帮忙解决下

问题描述 php开发遇到错误 Creating default object from empty value 求大神帮忙解决下 代码: 14 define('IN_ECS', true); 15 $smarty->left_delimiter = '<!--{'; 16 $smarty->right_delimiter = '}-->'; 17 require(dirname(__FILE__) . '/includes/init.php'); 18 if ((DEBUG_MOD

redis集群搭建的时候出现问题,大神帮忙解决下吧,谢谢了。

问题描述 redis集群搭建的时候出现问题,大神帮忙解决下吧,谢谢了. redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 到这一步的时候,报错: Creating cluster Connecting to node 127.0.0.1:7000: [ERR] Sorry, can't connect