在 none- UI 线程上使用 BitmapImage(或其他 UI 命名空间 类)是否有限制?

Is there a restriction on using a BitmapImage (or other UI namespace classes) on a none- UI thread?

我正在我的代码中执行一些涉及 BitmapImage 的云操作,并且在响应(基本上肯定是 none-UI 线程)我得到一个 "The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))" 在 -

BitmapImage cImage = new BitmapImage(); 

AFAK 这意味着我已经尝试从 none-UI 线程访问 UI,但我只是在实例化它,并没有尝试修改任何 ui 相关数据..

关于为什么会发生这种情况的任何想法?我是否被限制在 none-UI 线程上使用 UI 命名空间中定义的 class?

在Windows运行时,BitmapImageclass继承自DependencyObject,这将限制非UI线程的访问。所以你不能在非UI线程中操作BitmapImage对象,正如Aybe建议的那样,你需要使用UI线程调度程序。