An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Additional information: Cross-thread operation not valid: Control 'label1' accessed from a thread other than the thread it was created on.
Asked
Active
Viewed 527 times
-1
-
1Show some code so we will know how to help you – shahar eldad Feb 27 '17 at 14:21
-
[How do I ask a **good** question?](http://stackoverflow.com/help/how-to-ask) – marc_s Feb 27 '17 at 14:23
-
Possible duplicate of [Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on](http://stackoverflow.com/questions/142003/cross-thread-operation-not-valid-control-accessed-from-a-thread-other-than-the) – RB. Feb 27 '17 at 14:24
-
foreach (var update in updates) { offset = update.Id + 1; if (update.Message == null) continue; var From = update.Message.From.Username; var text = update.Message.Text; long ChatId = update.Message.Chat.Id; label1.Text = string.Format("Sender : {0}\nText : {1}\nChatID : {2}", From, text, ChatId); } – Ryvarz Feb 27 '17 at 14:29
-
Please post the code as text in the question itself: see [this article](http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question/285557) for an explanation of why. Also, posting code in the comments section doesn't count because it's unformatted and therefore unreadable. – EJoshuaS - Stand with Ukraine Feb 27 '17 at 15:01
1 Answers
0
If it is a winforms application you need to use invoke method to do updates to the control on the GUI thread (main thread). You tried to update the control from a background thread.
try something like label1.Invoke(() =>{ ... });

shahar eldad
- 861
- 1
- 12
- 31