For example, there is a client that communicates with the server, data arrives that needs to be partially output to the forms. I tried through Dispatcher , something still swears at STA . Maybe you need some background for the form update?

There is a calback method that is called when the socket finishes receiving data, it calls the function, the control changes in it depending on the response, the Dispatcher tried, it does not help, it requires the STA. Added [STAThread] for a Kalback socket, nothing helps, any ideas? thank

  • 3
    Possible duplicate question: Working with controls from the background thread - andreycha
  • Thank you, look - orion_gm
  • calling from ReceiveSocketCallback An exception was thrown: "System.InvalidOperationException" in PresentationCore.dll System.InvalidOperationException: The calling thread must be an STA, since most UI components require it. AuthWindow.Instance.UpdateErrorBoxMessage (AuthMessages.ErrorMessages [2]); <code> public void UpdateErrorBoxMessage (string message) {_tbErrors.Dispatcher.Invoke (new Action (() => _ _tbErrors.Text) = message;); } - orion_gm

1 answer 1

 private void AsyncHandler(object data) { tickCount++; Action action = () => textBox1.Text = tickCount.ToString(); if (InvokeRequired) { Invoke(action); } else { action(); } } 

or see examples of asynchronous c # programming with async and await operators