2

I am trying to build an application using the unofficial Google music api for .net in Windows 8 metro interface. I am loading the whole playlist

foreach (GoogleMusicPlaylist p in pls.UserPlaylists)
                lbPlaylists.Items.Add(p.Title);

and it comes up with this error

HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

And I read around the internet and maybe I have to use dispatcher or something I am just generally confused.

nkchandra
  • 5,585
  • 2
  • 30
  • 45
user673906
  • 757
  • 6
  • 15
  • 30
  • Are you, by any chance, trying to access the UI from any other thread than the UI-thread? :) – Patryk Ćwiek Oct 10 '12 at 14:59
  • @Trustme-I'maDoctor Yes you can see he is adding an item to a UIElement directly (this is not considered good practice, by the way). I think he likely just needs to use Dispatcher Invoke. – erodewald Oct 10 '12 at 15:03

1 Answers1

6

Use this

Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                foreach (GoogleMusicPlaylist p in pls.UserPlaylists)
                {
                    lbPlaylists.Items.Add(p.Title);
                }
            });
Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184