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

推荐订阅源

F
Fortinet All Blogs
Attack and Defense Labs
Attack and Defense Labs
V2EX - 技术
V2EX - 技术
O
OpenAI News
S
Secure Thoughts
H
Heimdal Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Schneier on Security
Schneier on Security
H
Hacker News: Front Page
S
Security Affairs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
The Register - Security
The Register - Security
GbyAI
GbyAI
Cloudbric
Cloudbric
MongoDB | Blog
MongoDB | Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
Forbes - Security
Forbes - Security
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
The Cloudflare Blog
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
Webroot Blog
Webroot Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
T
Tor Project blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
V
V2EX
T
Tailwind CSS Blog
SecWiki News
SecWiki News
NISL@THU
NISL@THU
C
Check Point 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();