Results 1 to 7 of 7

Thread: Listbox.Invoke Creates Infinite Loop

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    17

    Listbox.Invoke Creates Infinite Loop

    Hello all, I have a thread pool that calls a function and in the function it checks if invoke is required and if it is, it invokes the function and returns the value. Somehow this is creating an infinite loops and was wondering if you could help me find the problem. Heres my code:

    Code:
    private delegate string GetComboDelegate();
    
            private string GetCombo()
            {
                if (lbWordlist.InvokeRequired)
                {
                    return lbWordlist.Invoke(new GetComboDelegate(GetCombo)).ToString();
                }
                else
                {
                    while ((lbWordlist.Items[tbWordlist.Value - 1].ToString()).IndexOf(':') == -1)
                    {
                        tbWordlist.Value += 1;
                    }
                    string tmp = lbWordlist.Items[tbWordlist.Value - 1].ToString();
                    if (tbWordlist.Value == tbWordlist.Maximum)
                        StopBots = true;
                    else
                        tbWordlist.Value += 1;
    
                    return tmp;
                }
            }
    tbWordlist is a Trackbar that keeps track of my position in the Listbox.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Listbox.Invoke Creates Infinite Loop

    Where are you calling GetCombo from in the first place?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    17

    Re: Listbox.Invoke Creates Infinite Loop

    From the sub my thread pool is sent to

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Listbox.Invoke Creates Infinite Loop

    Quote Originally Posted by Spilled
    From the sub my thread pool is sent to
    I get that. Can you show us the code?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    17

    Re: Listbox.Invoke Creates Infinite Loop

    Code:
                    Image Img;
                    if (!Bot.GetImage(txtCaptcha.Text, out Img))
                    {
                        if(StopBots)
                            UpdateResponse(Info.id, "Bot Done...");
                        else
                            ThreadPool.QueueUserWorkItem(new WaitCallback(Begin), new BotData(Info.id, GetCombo(), Info.proxy, Info.url, Info.timeout));
                        return;
                    }

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    17

    Re: Listbox.Invoke Creates Infinite Loop

    Basically it downloads the Image I need, then queue's another work item with the new combo and returns

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Listbox.Invoke Creates Infinite Loop

    You said that you're calling GetCombo from the method that you're using as the entry point for your new thread. First up, you haven't shown us that method. Secondly, you're showing us code that calls GetCombo from the current thread, NOT the new thread. If that's the only place GetCombo is called then there's no need for delegation. If it's not the only place then please show us the other code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width