异步检索RSS提要时的System.Runtime.InteropServices.COMException

时间:2012-09-20 07:49:34

标签: c# exception asynchronous windows-8 microsoft-metro

我正在尝试构建一个Windows 8 metro应用程序。一个小的RSS阅读器,用于检索提要。

因此我尝试获取Feed异步。

Windows.Web.AtomPub.AtomPubClient client = new Windows.Web.AtomPub.AtomPubClient();
client.RetrieveFeedAsync(new Uri("http://MyURI/index.rss")).Completed += completed;

这是回调函数:

private void completed(IAsyncOperationWithProgress<Windows.Web.Syndication.SyndicationFeed, Windows.Web.Syndication.RetrievalProgress> asyncInfo, AsyncStatus asyncStatus);

确定。现在我的问题。

只要我尝试在回调函数中访问对象,一切都运行正常。但是如果我尝试访问我的类的对象(回调函数所在的对象),我得到了一个COMException。 我尝试这样的事情:this.MyCollection.Add(...)。我正在构建一个feedItem,我将其添加到我班级的一个集合中。

An exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll but was not handled in user code

Additional information: Eine Schnittstelle, die für einen anderen Thread marshalled war, wurde von der Anwendung aufgerufen. (Ausnahme von HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

If there is a handler for this exception, the program may be safely continued.

奇怪的是,这种访问在我的应用程序的每一次运行时都在运行。

我不明白这里出了什么问题。

有人请给我一个提示吗?

非常感谢!

1 个答案:

答案 0 :(得分:0)

确定。解决方案是BlockingCollection。它是线程安全的。