Sleep的问题
先上全部源码:
using System;
using System.Threading;
namespace MoveServices
{
public static class MoveWorker
{
private static Random random = new Random();
public static void DoWork()
{
while (true)
{
, );
Console.WriteLine("{0}\ttime={1}", DateTime.Now.ToString("HH:mm:ss.fff"), time);
Thread.Sleep(time > - ? time * : time);
}
}
}
}
using System;
using System.Threading;
namespace MoveServices
{
class Program
{
static void Main(string[] args)
{
while (true)
{
try
{
MoveWorker.DoWork();
}
catch (Exception exception)
{
Console.WriteLine("{0}\texception:{1}", DateTime.Now.ToString("HH:mm:ss.fff"), exception.Message);
}
finally
{
Thread.Sleep();
}
}
}
}
}
当随机数time=-1的时候,程序会无限暂停,因为Thread.Sleep(-1)相当于sleep(UINT_MAX)。不说了,只有吃过亏才会深刻理解。
随机推荐
- eclipse下开发简单的Web Service
service部分 在eclipse下新建一个动态web项目 在项目中新建一个service类 编写SayHello类的代码 package org.sunny.service; //包不要引用错了 ...
- CSS3伪类选择器 图示
- dom4j处理java中xml还是很方便的
http://blog.csdn.net/chenghui0317/article/details/11486271 输入: String flighter = RequestUtil.get(&qu ...
- android蓝牙4.0(BLE)开发之ibeacon初步
一个april beacon里携带的信息如下 ? 1 <code class=" hljs ">0201061AFF4C0002159069BDB88C11416BAC ...
- Quartz contention when running in load balanced environment--reference
1.8.3 appears to have addressed this issue with a single application server. However, we're seeing t ...
- GridView禁止上下滚动的方法
通常情况下,我们使用GridView来完成类似表格的布局,这种布局,我们只需要设置列数,会自动根据适配器的数据进行适配,非常灵活. GridView其实就是一个容器.允许向其内部添加控件,通常情况下, ...
- xUtils3源码分析(一):view的绑定
概述 xUtils3是国人开发的一款功能丰富的Android快速开发框架,值得研究下.zip包下载:[ZIP]xutils主要分以下几个模块 视图绑定模块 网络请求模块 数据库模块 图片加载模块 我们 ...
- (转)Css样式兼容IE6,IE7,FIREFOX的写法
根据FF和IE对一些符号识别的差异,我们可以单独对FF以及IE定义样式,例子: 区别IE6与FF: background:orange;*background:blue; 区别I ...
- Memcached报错
1. ERROR Memcached.ClientLibrary.SockIOPool [(.6271ms 解决办法:据说是因为定期清理应用池的原因.
- CoreLocation+MapKit系统定位(含坐标以及详细地址)
iOS8 之后出现一些新的配置 [self.manager requestWhenInUseAuthorization]; 并且在info.plist文件中增加 NSLocationWhenInUse ...