惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
博客园 - 【当耐特】
V
Visual Studio Blog
GbyAI
GbyAI
V
V2EX
P
Proofpoint News Feed
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
B
Blog RSS Feed
量子位
MongoDB | Blog
MongoDB | Blog
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件

博客园 - samuel's blog

想了很久,我决定换BLOG了. FANSMI音乐下载器原理 哈,俺又回来了! [原创]在C#中实现插件编程 [转]利用XMLHTTP无刷新自动实时更新数据 [转]SYN Flood的C++程序 - samuel's blog 觉得我的BLOG“好像”冷了哦! 师兄写的一个JAVA播放器的源代码 向面连接的ADO.NET 水晶报表的使用技巧 无聊,,,,,吼两声!!!!!!!!!!!!!!! 按需要生成你的"网站导航"栏 ASP.NET中使用托管组件 无聊之极的无聊之“作”,C#加密程序 八种和电脑相关的易发病 最近不更新啦! 看完了没一个能活下的,都笑死了[转] SQL SERVER的视图、存储过程等 国产门户网站和思想强奸!
启动带参数的线程
samuel's blog · 2007-07-12 · via 博客园 - samuel's blog

前个星期,公司的项目在客户那里出现了点问题,情况为电话打入后,系统不能弹单(打入电话的时候会显示打入电话者的三字段信息:名字、电话、地址),经过检查后,发现为系统在向GIS系统发送数据的时候造成一个超时等待(GIS没有启动,但是我不明白的是我用的UdpClient,按理说不应该出现这种情况啊),考虑后,决定使用线程来解决这个问题,但是这个线程需要以带参数的形式启动,经过思考后,得出以下代码:

// 首先要写一个类,类里头包含了数据的发送,以构造函数的方式将REMOTE HOST、PORT、和要发送的数据构造进去。
#region send gis data
 class SendGISData
 {
  private string strIP = "";
  private string strData = "";
  private int nRemotePort = -1;

  // IP:目标机IP地址,Data:要发送的字符串数据,RemotePort:端口
  public SendGISData(string IP,string Data,int RemotePort)
  {
   strIP = IP;
   strData = Data;
   nRemotePort = RemotePort;
  }

  public void UDPSendData()
  {
   int sendCount = 0;
   System.Net.Sockets.UdpClient client = new System.Net.Sockets.UdpClient(strIP,nRemotePort);
   byte[] data = new byte[strIP.Length];
   try
   {
    client.Connect(strIP,nRemotePort);
    data = Encoding.ASCII.GetBytes(strData);
    sendCount = client.Send(data,data.Length);
   }
   catch
   {
    sendCount = -32767;
   }
   finally
   {
    client.Close();
   }
  }
 }
 #endregion

// 使用方法
using System.Threading;
....
....
....
SendGISData GISCtrl= new SendGISData("10.54.163.164","02887832222",8080);
ThreadStart threadStart = new ThreadStart(GISCtrl.UDPSendData);
Thread thread= new Thread(threadStart);
thread.Start();