如何等待回调事件返回值

时间:2016-11-17 14:40:57

标签: c#

EIDReader eidObj;
static FancyPopup  fancyObj;

    Calss UIpdate
    {
       UIUpdate()
       {
          eidObj = new EIDReader();//only contact card                
          eidObj.DeviceArrival += eidObj_DeviceArrival;  
          eidObj.DataReceived += EIDReader_DataReceived;       
       }
    }

bool eidObj_DeviceArrival(stirng name)
{       
     //device arrived ,                         
      notifyIcon = new TaskbarIcon(this);
      notifyIcon.Icon = Resources.Led;
      notifyIcon.ToolTipText = DeviceName + " Reader Application";
      notifyIcon.Visibility = Visibility.Visible;    
      fancyObj = new FancyPopup();    
      notifyIcon.TrayPopup = fancyObj;
}

bool EIDReader_DataReceived(string[] CardData, string[] PublicData, System.Drawing.Image ImgPhoto)
{
   if (CardData != null)
   {
      fancyObj.ClickCount = PublicData[(int)EIDReader.eCardInfo.CSNValue];
      // Here fancyObj is NULL, so rising exception.  and i dont know why it  becomming NULL.
   }
  return true;
}

// in another class 
Class EIDReader{
    public delegate bool OnDeviceArrival(string DeviceName);
    public event OnDeviceArrival DeviceArrival;

   EIDReader()
   {
    if (DeviceArrival != null)
     {
       DeviceArrival(readerMgr.Readers[mDevType].ReaderName)
    // Here i need to wait for the callback return value since UI update are going in main form.
     }
   }    
}

我在UI表单中有很多回调事件,无论UI更新是否完成,我都需要等待每个事件。

e.g。在devicearrival回调事件中,我正在更新UI中的设备名称,但我不知道UI更新是否已完成。

调用datareceived()回调事件时,fancyobj实例为NULL。为什么即使我在另一个回调事件中初始化,fancyobj也会变为NULL。

0 个答案:

没有答案