Thursday, 22 August 2013

Using an anti-cross-thread function to return a value

Using an anti-cross-thread function to return a value

I have this code to get around the bane of everyone's existence
delegate int GetSelectedIndicesCountCallback(ListBox thing);
private int GetSelectedIndicesCount(ListBox thing)
{
if (this.InvokeRequired)
{
GetSelectedIndicesCountCallback d = new
GetSelectedIndicesCountCallback(GetSelectedIndicesCount);
Invoke(d, new object[] { thing });
}
else
{
return thing.SelectedIndices.Count;
}
return 0;
}
The return 0 being there because it'd error without it. However, it always
returns 0. I don't know how to get it to return the other value.

No comments:

Post a Comment