I am using delegates yet still getting
"cross thread operation not valid" errors.
This is the function I am calling from another form:
[CODE]
edit see below
[/CODE]
Cross Tread Operations
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
jesse4 pointsPosted Mar 7, 2009, 11:26 AM EST
I cannot get a function that returns, to be able to use a delegate correctly.
This code only returns "none" and never the selected item
[CODE]
private delegate string GetSelectedItemURLDelegate();
public string GetSelectedItemURL()
{
string returnUrl = "none";
if (this.PlaylistListbox.InvokeRequired)
{
this.PlaylistListbox.Invoke(new GetSelectedItemURLDelegate(this.GetSelectedItemURL));
}
else
{
if (PlaylistListbox.SelectedItem == null)
{
if (PlaylistListbox.Items.Count != 0)
{
PlaylistListbox.SelectedIndex = 0;
returnUrl = PlaylistListbox.SelectedItem.ToString();
}
}
else
{
returnUrl = PlaylistListbox.SelectedItem.ToString();
}
}
return returnUrl;
}
[/CODE]
jesse4 pointsPosted Mar 8, 2009, 1:31 PM EDT
[code]
private delegate string GetSelectedItemURLDelegate();
if (this.PlaylistListbox.InvokeRequired)
{
return this.PlaylistListbox.Invoke(new GetSelectedItemURLDelegate(this.GetSelectedItemURL)) as string;
}
else
{
[/code]