2010-12-01 52 views
1

調試古怪我有以下方法:與BeginInvoke的

protected void OnBarcodeScan(BarcodeScannerEventArgs e) 
{ 
    if (BarcodeScan != null) 
    { 
     //BarcodeScan.BeginInvoke(e, null, null); 
     BarcodeScan(e); 
    } 
} 

當我踏進它工作正常,上述方法。我能夠一遍又一遍地遍歷該方法的所有部分。

但是,如果切換註釋(所以BarcodeScan(e)被註釋掉,並取消對BarcodeScan.BeginInvoke(e, null, null)評論我就不能踏入OnBarcodeScan方法的任何部分(即在if (BarcodeScan != null)一個破發點並沒有被擊中。

我試着把一些調試語句放在那裏,但是隻要那個開始調用調用就在那裏,它不會讓我進入方法

我檢查了輸出,當我嘗試插入它說:

ScannerTest.exe中發生類型'System.NotSupportedException'的第一次機會異常 單步執行:單步執行不帶符號的方法'Symbol.Marshaller.SymbolMessageWindow.WndProc' 單步執行:單步執行不帶符號的方法'Microsoft.WindowsCE.Forms .MessageWindow._WndProc'

爲什麼整個方法在其中存在BeginInvoke時無法執行?

任何幫助將是偉大的!

+0

您使用的是什麼版本的Visual Studio? – JaredPar 2010-12-01 23:49:46

+0

你有沒有試過插入`Debugger.Break()`語句?有時候,如果斷點沒有被擊中,這會有所幫助... – Lucero 2010-12-02 00:03:26

回答

4

Compact Framework不支持異步委託調用(即BeginInvoke)。

至於爲什麼調試器甚至不會闖入方法的原因,我認爲這是由於以下原因:由C#編譯器生成

  • BeginInvoke/EndInvoke方法(這是required to do this)標記爲「本地」。這意味着CLR將提供實施。
  • 精簡版框架CLR does not provide the implementation
  • 當JIT編譯器第一次執行一個方法時,它會查找它可能調用的所有方法(加載其他程序集等)。
  • 由於CLR不支持Delegate.BeginInvoke,因此調用它的任何方法都不能進行JIT編譯,因此無法執行。
  • OnBarcodeScan第一次調用時(和JIT編譯器嘗試編譯它並失敗),將引發NotSupportedException。這就是調試器無法實現的原因。