如何避免这种异常? [英] How to avoid this exception?
问题描述
大家好,
[复制步骤]
1.创建一个新的UnitTest项目
2.在TEST_METHOD范围内输入这些代码
Windows :: UI :: Xaml :: Media :: Imaging :: BitmapImage ^ FileThumbnail; FileThumbnail =引用新的Windows :: UI :: Xaml :: Media :: Imaging :: BitmapImage();
3.运行UnitTest
4.获取异常
消息:未处理的WinRT异常:Platform :: WrongThreadException
此异常应由ref new BitmapImage()引起
但我不知道该如何处理
我的问题:
为什么会发生此异常?
如何避免这种异常?
谢谢
Windows :: UI :: Xaml元素(例如BitmapImage)需要在您的UI线程上创建.>
我不确定如何(或是否)可以通过UnitTest进行此操作,但是测试工具"论坛中的某人可能可以提供帮助.
-Rob
Hi all,
[Reproduce Step]
1.Create a new UnitTest project
2.Input these code in TEST_METHOD scope
Windows::UI::Xaml::Media::Imaging::BitmapImage^ FileThumbnail; FileThumbnail = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage();
3. Run UnitTest
4. Get exception
Message: Unhandled WinRT Exception: Platform::WrongThreadException
This exception should be cause by ref new BitmapImage()
But I don't know how to handle this section
My question:
Why occur this exception?
How to avoid this exception?
Thanks
Windows::UI::Xaml elements such as BitmapImage need to be created on your UI thread.
I'm not sure how (or if) you can do this from a UnitTest, but somebody in the Test Tools forum may be able to help with that.
--Rob
这篇关于如何避免这种异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!