Exception on BitmapFrame.Create (bug in WPF framework?)

后端 未结 4 1831
借酒劲吻你
借酒劲吻你 2021-01-11 16:17

I implemented a C# application that recevies frame RGB at framerate of 30fps.

The event of frame arrive is managed with this code:

void client_ColorFra         


        
4条回答
  •  鱼传尺愫
    2021-01-11 16:50

    This is by design. A first-chance exception notification doesn't mean that there's a problem. The relevant code inside the Create() method looks like this:

    try
    {
        metadata = source.Metadata as BitmapMetadata;
    }
    catch (NotSupportedException)
    {
    }
    

    In other words, the exception is expected and simply swallowed. Which is certainly very annoying since these exceptions do make the debugger stop when you have the Thrown checkbox checked in the Debug + Exception dialog. But it certainly is not a bug, this was intentionally written this way. Sometimes it is a lot cheaper to just let an exception be thrown and swallowing it instead of writing the code that prevents the exception. Especially when it gets unpractical to avoid the exception, the case with bitmaps since there are so many different kind of bitmap types. Some of which don't support metadata. Wherever this is done inside the framework code, it is almost always done to make the code faster. Speed is also an important aspect of code.

    Feature, not a bug. Untick the Thrown checkbox to avoid seeing these exceptions.

提交回复
热议问题