Inumedia / SlackAPI

.NET Implementation of the Slack team communication platform API.
MIT License
452 stars 243 forks source link

TargetInvocationException #4

Closed steventhorne closed 9 years ago

steventhorne commented 9 years ago

I subscribe to the OnMessageReceived event in SlackSocketClient. I'm using wpf and I'm trying to set the text of the TextBlock when I get a new message, but if I set the text in the function that is attached to the OnMessageReceived event it gives me a TargetInvocationException.

Inumedia commented 9 years ago

This sounds like an issue with WPF to me, could you provide some test code so I can have a better understanding of the issue?

I know in WinForms you have to be on the graphics thread to adjust any values of a control, maybe that applies here as well?

steventhorne commented 9 years ago

http://pastebin.com/Lgnp7eW9

I'm instantiating this class in the MainWindow constructor which is the xaml.cs class.

I've also tried using JSON.net to deserialize json in an OnMessageReceived event and that gives me the same exception.

steventhorne commented 9 years ago

Ok so you were right about the graphics thread. I used the Dispatcher.Invoke of m_MainWindow to change the ui and there are no more issues, but I am still curious about why I couldn't do the JSON.net stuff, I'm going to attempt it again.

Inumedia commented 9 years ago

Has this issue been resolved then?

steventhorne commented 9 years ago

I would say so, sorry about causing a ruckus and thanks for the help!

Inumedia commented 9 years ago

Not a problem, glad I could help. :)