ThreadStart entryPoint = new ThreadStart(monitor.match_response);
try
{
Thread thread_match_response = new Thread(entryPoint);
thread_match_response.IsBackground = true;
thread_match_response.Start();
}
catch (Exception ex)
{
Addlog.addlog("thread_match()" + ex.Message);
}match_response这个是死循环的程序,我重新开了一个线程,单核CPU一运行这个程序就CPU100%.这个是要怎么改?
try
{
Thread thread_match_response = new Thread(entryPoint);
thread_match_response.IsBackground = true;
thread_match_response.Start();
}
catch (Exception ex)
{
Addlog.addlog("thread_match()" + ex.Message);
}match_response这个是死循环的程序,我重新开了一个线程,单核CPU一运行这个程序就CPU100%.这个是要怎么改?
双核的机器也会有一个核占用100%的。需要这么写么?需求就是这样子的?如果是想要判定某个属性是否匹配上了可以像下面这么写。
public class MatchHelper
{
public delegate void MatchCallback(YourNeededParams something);
public YourMatchType Src{get;set;}
private YourMatchType match;
public YourMatchType Match
{
get{ return match; }
set
{
match = value;
if(Src.Equals(match))
{
MatchCallback(params);
}
}
}
}
楼主可以考虑这么的。
Thread.Sleep(200);
让它空出200毫秒做其他东西
//释放控制权给程序
System.Threading.Thread.Sleep(0);
我那个死循环是不停的捕捉socket的消息,所以只能死循环
如果非要这么循环着来,Socket的Receive是阻塞的,Blocking设置为true就好了。