Lachee / discord-rpc-csharp

C# custom implementation for Discord Rich Presence. Not deprecated and still available!
MIT License
579 stars 96 forks source link

[BUG] Different Thread Exception #152

Closed Mrgaton closed 3 years ago

Mrgaton commented 3 years ago

a bug in rpc tryng to change a form label form ready image i have thath code but when i tried to run it i have this error

System.InvalidOperationException: Invalid operation through threads: The control 'BiembenidaLabel' was accessed from a different thread than the one in which it was created. in System.Windows.Forms.Control.get_Handle () in System.Windows.Forms.Control.set_WindowText (String value) in System.Windows.Forms.Control.set_Text (String value) at K1R4FN.K1R4FN. d__34.MoveNext () at C: \ Users \ Mrgato \ source \ repos \ K1R4FN \ K1R4FN \ K1R4FN.cs: line 261

Lachee commented 3 years ago

This isn't a bug.

By default, events are emitted on the thread that created them (the IO thread). You cannot update WinForm elements from different threads.

There are multiple solutions to this problem. A quick google search for the issue would have lead you to this solution.

The documentation contains further reading about how events work.