What does this mean?

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
 
J

Jeff Johnson

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.
 
J

Jeff Johnson

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.
 
A

Anders Eriksson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top