montaque

小碗喝酒,小口吃肉

博客园 首页 新随笔 联系 订阅 管理
微软产品的 Bug 真是千奇百怪,今天分享一个同事碰到的问题.

问题的描述: 使用了三个 System.Threading.Timer 分别在每天的三个时间点执行一个固定的统计操作,结果发现过了一段时间后, 这三天timer 的事件出发都到同一个时间点上去了,感觉有点想三个手表都没有电池一样,stop 在同一个时间点.哈哈,后来差了一下kb,这个也是微软的一个bug,到现在还没有提供公共的fix,只能找技术中心索取一个kb.

如果您也是用这个组件一定要小心, 否则可能造成很大的数据不一志:

代码如下:
private void Form1_Load(object sender, System.EventArgs e)
        
{

            System.Diagnostics.TextWriterTraceListener trace1
=new System.Diagnostics.TextWriterTraceListener("c:\\a.txt","fsd");
            System.Diagnostics.Trace.Listeners.Add(trace1);    
        
        }


        System.Threading.Timer t1;
        System.Threading.Timer t2;
        
private void button2_Click(object sender, System.EventArgs e)
        
{
            t1
=new System.Threading.Timer(new System.Threading.TimerCallback(Test),null,0,10000) ;
                        
            t2
=new System.Threading.Timer(new System.Threading.TimerCallback(Test1),null,0,10000) ;
        }


        
private void Test(object o)
        
{
            System.Diagnostics.Trace.WriteLine( 
" worker 1 ;   " + DateTime.Now.ToString() + "---tickcount---" + System.Environment.TickCount.ToString());
            System.Diagnostics.Trace.Flush();
        }


        
private void Test1(object o)
        
{
            System.Diagnostics.Trace.WriteLine( 
" worker 2 ;   " + DateTime.Now.ToString() + "---tickcount---" + System.Environment.TickCount.ToString());
            System.Diagnostics.Trace.Flush();
        }


如果有可能的话,你可以让这个程序连续运行 50 天,也就是让 Enviornment.Tickcount> 49.7*24*60*50*1000 的话,最后显示出来的时间就是一摸一样的,hoho.


到现在,我们也不太在production环境中使用hotfix,只能是在程序快运行到49天的时候,重启一下


最后的问题是,您能在短时间内重现这个问题吗?

posted on 2005-02-16 17:34  montaque  阅读(1812)  评论(8编辑  收藏  举报