views:

52

answers:

2

Using VC# 2008, in WinXP 32 bit, the following function

 private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        textBoxURL.Text = webBrowser1.Url.ToString();
        if (bStart)
        {
            string strData= webBrowser1.DocumentText;
            int iIndex = listBox1.Items.IndexOf(strID);

            if (strData.Contains("No news found"))
            {
                listBox1.SetSelected(iIndex, false);
                listBox1.Items[iIndex] = getID((string)listBox1.Items[iIndex]);
            }
            else
            {
                listBox1.Items[iIndex] = getID((string)listBox1.Items[iIndex]) + "; ONLINE";
                if (!listBox1.GetSelected(iIndex))
                {
                    timer2.Enabled = true;
                    listBox1.Items[iIndex] = getID((string)listBox1.Items[iIndex]) + "; MOVING";
                }
            }

            timer1.Interval = iTime + rand.Next(iTimeVar);
            timer1.Enabled = true;
        }
    }

When the listbox1.SetSelected(iIndex,false) line executes, the function just seems to return right there. Same with any of the lines that access listbox member functions.

Is that supposed to happen? Is there some way around that?

A: 

What's likely happening is the line listbox1.SetSelected(iIndex,false) is throwing an exception. If you are stepping through this is in the debugger and have exception notifications disabled it will look just like the function stopped executing at that point.

Try turning on first chance exception notifications and seeing if it reveals a problem. Go to

  • Debug -> Exceptions
  • Check the "Thrown" box for Common Language Runtime

Also disable the "Just My Code" Option in Visual Studio

  • Tools -> Options -> Debugger
  • Uncheck "Enable Just My Code"
JaredPar
This also leads to the answer, but it'll only let me give it to one and the other guy had it right on the head. Thanks for the help and the great tip!
dunecat
+1  A: 

Check the value of iIndex.

More than likely that index is out of bounds (i.e. because the string you are trying to locate is not contained in the list) and the line of code is throwing an exception.

Jeff Leonard
That's exactly it. THANKS!
dunecat