C# 无法强制转换类型为';系统。共对象';至接口类型';IImageList';

C# 无法强制转换类型为';系统。共对象';至接口类型';IImageList';,c#,shell,C#,Shell,我用它来提取超大图标。只要我从UI线程调用它的方法GetIcon,一切都正常。但是如果我从另一个线程调用,它会抛出这个错误 Unable to cast COM object of type 'System.__ComObject' to interface type 'IImageList'. This operation failed because the QueryInterface call on the COM component for the interface with II

我用它来提取超大图标。只要我从UI线程调用它的方法GetIcon,一切都正常。但是如果我从另一个线程调用,它会抛出这个错误

Unable to cast COM object of type 'System.__ComObject' to interface type 'IImageList'. 
This operation failed because the QueryInterface call on the COM component for the interface with IID 
'{46EB5926-582E-4017-9FDF-E8998DAA0950}' failed due to the following error: 
No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

我无法使用UI线程提取数千个图标。有解决方案吗?

请确保在工作线程而不是UI线程上调用SHGetImageList。确保您使用线程并调用SetApartmentState()使其成为STA。是的,当我在需要使用IconIndex的同一线程中使用构造函数时,问题已得到修复。但我仍然不明白它为什么会这样反应。没有为该接口注册代理。请确保在工作线程上调用SHGetImageList,而不是在UI线程上。确保您使用线程并调用SetApartmentState()使其成为STA。是的,当我在需要使用IconIndex的同一线程中使用构造函数时,问题已得到修复。但我还是不明白为什么它会有这样的反应。这个接口没有注册代理。