Skip to content

Cross Tread Operations

jesse

Asked Mar 7, 2009, 9:33 AM EST2 answers
Share
LinkedInX
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]

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Actually i got the question from above to work.  Now I have a different question.
    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]
    0
  • 0
    Well I figured it out:

    [code]
     private delegate string GetSelectedItemURLDelegate();
                if (this.PlaylistListbox.InvokeRequired)
                {
                    return this.PlaylistListbox.Invoke(new GetSelectedItemURLDelegate(this.GetSelectedItemURL)) as string;
                }
                else
                {
    [/code]
    0