当前位置: 代码迷 >> C# >> WCF服务与THREAD.TIMEr有关问题
  详细解决方案

WCF服务与THREAD.TIMEr有关问题

热度:43   发布时间:2016-05-05 04:58:15.0
WCF服务与THREAD.TIMEr问题
客户端调用WCF服务用于将数据写入WCF服务中定义的一个队列,在WCF服务中开一牙Thread.Timer进行监听。代码如下:
WCF服务
 private  Queue<DataTable> transpondQueue = new Queue<DataTable>();      
        public bool TranspondMsg(DataTable tMsg_datatable)
        {
          
            lock (this)
            {
              
                transpondQueue.Enqueue(tMsg_datatable);
                int good = transpondQueue.Count;
               
                return transpondQueue.Count>0;
            }
        }
Thread.Time
 private void QuerySMS()
        {
          
            int time = FileManager.GET_queryintervaltime();        //获取TIME执行间隔             
            querytime = new Timer(QuerySms_Elapse, null, 0, time);// Timer(QuerySms_Elapse, null, 0, time);
        }

  private void QuerySms_Elapse(object odata)
        {
                      
            while (transpondQueue.Count>0)//for (int 
           {
            ………………
              }
}
问题,当transpondQueueg更新后,在QuerySms_Elapse方法中读取到的QuerySms_Elapse.Count总是小于0。若将此队列更改成字符串后,在此方法中读到的也是其初始值。不知为什么会这样?客户端调用是成功的,返回TRUE.
------解决思路----------------------
private static Queue<DataTable> transpondQueue = new Queue<DataTable>(); 
  相关解决方案