开发者

Debugging weirdness with BeginInvoke

I have the following method:

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

When I try to step into the above method it works fine. I am able to step in and over all the parts of the method.

However, if I switch the comment (so BarcodeScan(e) is commented out and remove the comment on BarcodeScan.BeginInvoke(e, null, null) then I cannot step into any part of the OnBarcodeScan method (ie a break point on if (BarcodeScan != null) does not get hit.

I tried putting some debug statements in there too. But as long as that begin invoke call is in there it does not let me step into the method.

I checked the output and when I try to step in it says this:

A first chance exception of type 'System.NotSupportedException' occurred in ScannerTest.exe Step into: Stepping over method without symbols 'Symbol.Marshaller.SymbolMessageWindow.WndProc' Step into: Stepping over method without symbols 'Microsoft.WindowsCE.Forms.MessageWindow._WndProc'

Why would the whole method be un step able when there is a BeginInvoke in it?

Any help开发者_如何学编程 would be great!


Asynchronous delegate calls (i.e., BeginInvoke) are not supported by the Compact Framework.

As to the reason why the debugger will not even break into the method, I believe it is because of the following:

  • BeginInvoke/EndInvoke methods are generated by the C# compiler (it is required to do this), marked as "native". This means the CLR will provide the implementation.
  • The Compact Framework CLR does not provide the implementation.
  • When the JIT compiler executes a method for the first time, it looks up all of the methods it may call (loading other assemblies, etc).
  • Since the CLR doesn't support Delegate.BeginInvoke, any method that calls it cannot be JIT-compiled, and therefore cannot be executed.
  • The NotSupportedException is thrown when OnBarcodeScan is first called (and the JIT-compiler attempts to compile it and fails). This is why it cannot be stepped into by the debugger.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜