简体   繁体   中英

Array Index Out Of Bounds

Index was outside the bounds of the array error occurs when trying to access a website, the first line in code below pops up with the error, and any alteration to it results in more of the same errors to the lines below that. Am I just not using a big enough array or is my code all flustered so I'm running bad numbers?

We Start by scraping pages with a regex expression:

                string[] lines = TextBox1.Lines;
                label2.Text = "Custom URL Status: Working";
                this.working.Text = "Fetching Web URL(s)";
                try
                {
                    WebBrowser browser = this.WebBrowser1;
                    browser.ScriptErrorsSuppressed = true;
                    for (int i = 0; i < lines.Length; i++)
                    {
                        browser.Navigate(lines[i]);
                        this.BrowserWait(this.WebBrowser1);
                        string[,] parameter = (string[,])this.preg_match(@"([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}[:][0-9]{1,5})", browser.Document.Body.InnerHtml);
                        if ((parameter[0, 0] == "") | (parameter[0, 0] == null))
                        {
                            this.t = new Thread(new ThreadStart(this.getFromSite1));
                            this.t.Start();
                            label2.Text = "Custom URL Status: Error";
                            return;
                        }
                        this.t = new Thread(new ParameterizedThreadStart(this._Lambda1));
                        this.t.Start(parameter);
                        browser = null;
                    }
                }

This is called:

        private void _Lambda1(object a0)
        {
        this.handleList((string[,])a0);
        }

Which errors on the first line of this.ToolStrip:

        public void handleList(string[,] tmp)
        {
        Control.CheckForIllegalCrossThreadCalls = false;
        this.ToolStripProgressBar1.Maximum = (int)Math.Round((double)(Convert.ToDouble(tmp[2, 0]) - 1.0));
        this.ToolStripProgressBar1.Minimum = 0;
        this.ToolStripProgressBar1.Value = 0;
        int num2 = (int)Math.Round((double)(Convert.ToDouble(tmp[2, 0]) - 1.0));
        for (int i = 0; i <= num2; i++)
        {
            this.ToolStripProgressBar1.Value = i;
            this.proxies.Text = Convert.ToString(this.iWork) + "/" + Convert.ToString(this.iTotal);
            this.iTotal++;

You make sure parameter[0, 0] is not null or empty, so why don't you check if parameter[2, 0] is assigned there as well?

Seeing the contents of the variable is as easy as a breakpoint or a line in the log file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM