I’m trying to build a windows 8 metro app. A small RSS reader which retrieves feeds.
Therefor I try to get a feed async.
Windows.Web.AtomPub.AtomPubClient client = new Windows.Web.AtomPub.AtomPubClient();
client.RetrieveFeedAsync(new Uri("http://MyURI/index.rss")).Completed += completed;
Here is the callback function:
private void completed(IAsyncOperationWithProgress<Windows.Web.Syndication.SyndicationFeed, Windows.Web.Syndication.RetrievalProgress> asyncInfo, AsyncStatus asyncStatus);
Ok. Now my problem.
As long as I try to access object within my callback function, everything is working fine. But if I try to access objects of my class (in which the callback function is located) I got a COMException.
I try something like this: this.MyCollection.Add(…). I’m building a feedItem which I add to a collection within my class.
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.
The strange thing is, that this access is working every second run of my app.
I don’t understand whats going wrong here.
Does someone got a hint for me please?
Thanks a lot!
Ok. The solution is a BlockingCollection. It is threadsafe.