【发布时间】:2012-09-20 07:49:33
【问题描述】:
我正在尝试构建一个 Windows 8 Metro 应用程序。一个小型 RSS 阅读器,用于检索提要。
因此,我尝试获取异步提要。
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.
奇怪的是,这种访问在我的应用程序的第二次运行中都有效。
我不明白这里出了什么问题。
请问有人给我提示吗?
非常感谢!
【问题讨论】:
-
好的。解决方案:BlockingCollection。
标签: c# exception asynchronous windows-8 microsoft-metro