0

我似乎無法爲在線問題找到一個很好的解決方案。我有一臺運行Windows Embedded Handheld 6.5的設備。我跑位於下方Windows Moible 6.5 SDK GPS示例Bugged

C:\Program Files (x86)\Windows Mobile 6.5.3 DTK\Samples\PocketPC\CS\GPS 

我的代碼部署到我的設備,而不是一個仿真器的解決方案,並在

Invoke(updateDataHandler); 

代碼打破了一個空引用異常看到的解決方案IVE建議更改本to below

BeginInvoke(updateDataHandler); 

但是現在代碼在Main處出現NullRefreceException異常。

Application.Run(new Form1()); 

有沒有人找到解決方案?

回答

1

你改變了代碼嗎? updateDataHandler在Form_Load中初始化:

private void Form1_Load(object sender, System.EventArgs e) 
    { 
     updateDataHandler = new EventHandler(UpdateData); 

使對象不會爲NULL。但是代碼還有其他一些煩惱,特別是Samples.Location類。您可以改爲使用http://www.hjgode.de/wp/2010/06/11/enhanced-gps-sample-update/作爲起點和較舊的:http://www.hjgode.de/wp/2009/05/12/enhanced-gps-sampe/

該示例的主要問題是它不使用回調(委託)來更新UI。如果從後臺線程觸發事件處理程序,則處理程序無法直接更新UI。以下是我經常用來從處理程序更新UI的內容:

delegate void SetTextCallback(string text); 
    public void addLog(string text) 
    { 
     // InvokeRequired required compares the thread ID of the 
     // calling thread to the thread ID of the creating thread. 
     // If these threads are different, it returns true. 
     if (this.txtLog.InvokeRequired) 
     { 
      SetTextCallback d = new SetTextCallback(addLog); 
      this.Invoke(d, new object[] { text }); 
     } 
     else 
     { 
      txtLog.Text += text + "\r\n"; 
     } 
    }