What does this mean?

  • Thread starter Thread starter Anders Eriksson
  • Start date Start date
A

Anders Eriksson

I have found this code on the internet. It works, but I don't understand
what it does.

Action action = () => lbMsg.Items.Add(msg);
Dispatcher.Invoke(action);

I'm using this for updating a listbox from an another thread.

// Anders
 
I have found this code on the internet. It works, but I don't understand
what it does.

Action action = () => lbMsg.Items.Add(msg);
Dispatcher.Invoke(action);

I'm using this for updating a listbox from an another thread.

I don't know if you're asking for a clarification of the SYNTAX or the
PURPOSE. As far as purpose goes, this is a classic example of how to
interact with a control (which, in a WinForms app, can only safely be done
from the UI thread) from a thread that is NOT the UI thread.
 
I just happened to read an article yesterday that talked about this
Dispatcher object. It seems it's part of WPF, so just change my comment
about WinForms on the previous reply to WPF. Same principle.
 
What part don't you understand?
the () => part

Thanks for your answer. I have tried to search but Google doesn't like
searching for things like =>

I understand what the code does now...
maybe I need to read up on LINQ, have avoided so far but...

// Anders
 
Back
Top