I have this code on different thread:
string sub = "";
this.BeginInvoke((Action)(delegate()
{
try
{
sub = LISTVIEW.Items[x].Text.Trim();
}
catch
{
}
}));
MessageBox.Show(sub);
what I want is to get the value of “LISTVIEW.Items[x].Text.Trim();” and pass it to “sub”. please note that the LISTVIEW control is on the main thread. now how can I accomplish this?
enter code here
You, of course, need to be a bit careful with EndInvoke because it can cause deadlocks.
if you prefer delegate syntax you can also change
to
you stll need to return something from all branches and call end invoke.