It is a lambda operator and reads as "going." MSDN has a good introduction: Lambda Expressions (C # Programming Guide)
One of the problems in your example is that you create a new thread for updating the user interface, the user interface is essentially single-threaded, so updating the background is usually not as it should (unless you manually or explicitly check InvokeRequired and invoke Invoke() if necessary Invoke() .
Regarding user interface streaming ...
In WinForms, each Form or Control is created in a specific thread (a "user interface thread"), and you may think that this thread is the owner of this control (not quite correct, but a good way to conceptualize it). Updating the user interface from this thread is safe, updating the user interface from another thread causes the risk of collisions and corruption and all the usual risks of parallel / asynchronous programming.
... So ... how do you safely update the user interface from a background thread without blocking the user interface? In short - you cannot - the best thing you can do is to block it for the minimum minimum required to update the user interface. Here InvokeRequired and Invoke() come in ...
Here is an example: you can leave this in the code for the new form using the button and text field.
Use:
Try commenting on the call to SetTextAsyncSafe() or SetTextAsyncSafe() - running both of them can be confusing since they will not necessarily be executed in the order in which they are called (they work async, remember?).
Then set a breakpoint on SetText() . You should see that the "safe" call will actually call this method twice - the first call will detect InvokeRequired and call the 2nd time method for the correct Invoke() 'stream to it.
You should see that Exception is SetTextAsyncUnsafe() when SetTextAsyncUnsafe() does receive textBox1.Text = value; . An exception will be an InvalidOperationException with a message stating that the Cross-Stream operation is invalid - you can use this term for this site for more details.
The code:
private void button1_Click(object sender, EventArgs e) { SetTextAsyncSafe("This update was made from the UI Thread by using Invoke()"); SetTextAsyncUnsafe("This update was made directly from the background thread and can cause problems"); } private void SetTextAsyncUnsafe(string value) { new Thread(() => SetText(value, false)).Start(); } private void SetTextAsyncSafe(string value) { new Thread(() => SetText(value, true)).Start(); } private void SetText(string value, bool checkInvokeRequired) { if (checkInvokeRequired) { if (InvokeRequired) { Invoke(new Action(() => SetText(value, checkInvokeRequired))); return;
source share