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]
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
jessePosted Mar 8, 2009, 5:31 PM
[code]
private delegate string GetSelectedItemURLDelegate();
if (this.PlaylistListbox.InvokeRequired)
{
return this.PlaylistListbox.Invoke(new GetSelectedItemURLDelegate(this.GetSelectedItemURL)) as string;
}
else
{
[/code]
jessePosted Mar 7, 2009, 4:26 PM
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]