none
多线程webBrowser的AccessViolationException异常 RRS feed

  • 问题

  • 采用多个线程分别控制一个webBrowser,同时加载不同网页,然后读取其中的Document。可是会不定期地抛AccessViolationException异常. 抛出异常后,如果在Debug中,直接F5执行下面语句不会对程序结果又任何影响,但是还是会不定期的再次抛出这个异常

            void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                //throw new NotImplementedException();
                if(((WebBrowser)sender).ReadyState<WebBrowserReadyState.Complete)

                 return;
                 System.Windows.Forms.HtmlDocument document = webBrowser.Document;                     //就是在这句访问webBrowser的时候抛出异常,
                 shopInfoQueue.Enqueue(shopInfo);
                 htmlContentQueue.Enqueue(document.Body.InnerHtml);

             }

    不明白为什么会不定期出错,并且继续执行并不影响结果,最主要的,这个怎么解决,或者能否屏蔽该异常

    2012年7月11日 7:12

全部回复

  • 根据MSDN,你是否在你的Main方法中,使用了STAThreadAttribute属性?
    2012年7月11日 21:57
  • 根据MSDN,你是否在你的Main方法中,使用了STAThreadAttribute属性?

    主线程没有,不过主线程创建的那几个控制webBrowser的线程都使用了  t.serApartmentState(ApartmentState.STA);
    2012年7月12日 1:21
  • WebBrowser控件本身是STA组件,所以,创建WebBrowser的线程需要是STA。通常,UI组件是在UI线程中初始化,所以,建议把Main方法设为STA再试试。如果还不行,再想别的方法。
    2012年7月12日 1:39
  • WebBrowser控件本身是STA组件,所以,创建WebBrowser的线程需要是STA。通常,UI组件是在UI线程中初始化,所以,建议把Main方法设为STA再试试。如果还不行,再想别的方法。

    设置主线程的ApartmentState, Thread.CurrentThread.SetApartmentState(ApartmentState.STA),会抛出InvalidOperationException异常,Failed to set the specified COM apartment state....

    是设置的方法不对?还是??

    2012年7月12日 5:02
  • 需要在Main方法上设STAThreadAttribute属性,因为COM套间的类型是不能够改变的。

    大概是如下的方式,你试试

    [STAThread]
    void Main()

    2012年7月12日 8:13
  • 需要在Main方法上设STAThreadAttribute属性,因为COM套间的类型是不能够改变的。

    大概是如下的方式,你试试

    [STAThread]
    void Main()


    好的,多谢,我试下
    2012年7月13日 2:21
  • 需要在Main方法上设STAThreadAttribute属性,因为COM套间的类型是不能够改变的。

    大概是如下的方式,你试试

    [STAThread]
    void Main()


    还是不行,运行一段时间之后还是同样的错误
    2012年7月13日 5:05
  • 应该是多线程调用WebBrowser出错了,能多贴一些你的代码,或者传个能重现问题的小Project么?
    2012年7月13日 6:46
  • 应该是多线程调用WebBrowser出错了,能多贴一些你的代码,或者传个能重现问题的小Project么?

     public void Init()                                        //每个线程有自己的form和WebBrowser                                                                                          
            {
                lock (lockMemory)
                {
                    this.form = new Form();
                    this.webBrowser = new WebBrowser();
                    this.form.Controls.Add(webBrowser);
                }
                form.WindowState = FormWindowState.Minimized;
                form.Visible = false;
                form.ShowInTaskbar = false;
                this.webBrowser.ScriptErrorsSuppressed = true;
                this.webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);

                Begin();
            }

     

    public void Begin()
            {

                lock (lockProgram)
                {
                    cnt = Program.shopListOffset++;                                                                     
                    if (cnt >= Program.totalCount)
                    {
                        Console.WriteLine("Finish!");
                        System.Threading.Thread.CurrentThread.Abort();
                    }
                    shopInfo = Program.shopInfoQueue.Dequeue();                                 //从队列中取URL
                }

                this.webBrowser.Navigate(getUrl(shopInfo));
                if(form.Visible==false)
                    form.ShowDialog();
            }

           void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                if (((WebBrowser)sender).ReadyState < WebBrowserReadyState.Complete)
                    return;
             waitSomeTime();
            }

      public void waitSomeTime()                                        //需要在页面加载完成后等待2秒才能取到要取的内容
            {
                
                timer = new System.Windows.Forms.Timer();
              
                timer.Interval = 2000; //2秒啓動
                timer.Tick += new EventHandler(Timer_Tick);
                timer.Start();
            }
            private void Timer_Tick(object sender, EventArgs e)
            {
                lock (lockHtmlContentQueue)
                {
                    System.Windows.Forms.HtmlDocument document= this.webBrowser.Document;        //这句出错
                    shopInfoQueue.Enqueue(shopInfo);
                    htmlContentQueue.Enqueue(document.Body.InnerHtml);

                }

                     Begin();

          }

    这些就是一个线程要做的事情,大概就是从队列里取出URL,打开网页,等两秒钟然后取出网页的Document,最后把document.Body.InnerHtml存到另一个队列,然后再重新开始这么一个过程。

    多谢指点了

    2012年7月13日 10:00
  • WebBrowser需要创建在UI线程中,且该线程中需要有消息循环。你能把Init()的调用的代码贴出来么?每个线程怎么创建,是否有消息循环,都很重要。
    2012年7月13日 17:54
  • WebBrowser需要创建在UI线程中,且该线程中需要有消息循环。你能把Init()的调用的代码贴出来么?每个线程怎么创建,是否有消息循环,都很重要。
               

      static void Main(string[] args)
            {
                int maxThreadCount = Int32.Parse(Console.ReadLine());

                System.Threading.Thread[] t = new Thread[maxThreadCount];
                GoogleMap[] gmc = new GoogleMap[maxThreadCount];

                for (i = 0; i < maxThreadCount; i++)
                {
                    gm[i] = new GoogleMap();
                    t[i] = new Thread(gm[i].Init);
                    t[i].SetApartmentState(System.Threading.ApartmentState.STA);
                    t[i].Start();
                }

    }

    2012年7月16日 1:32
  • 你的线程中没有消息循环,线程似乎应该很快就退了,建议在Init()最后,加上一句:

    Application.Run(this.form);

    2012年7月16日 7:42
  • 你的线程中没有消息循环,线程似乎应该很快就退了,建议在Init()最后,加上一句:

    Application.Run(this.form);

    因为是几个线程共用一个form,所以用form.showdialog(),可以跟这个application起到一样的效果

    最开始的时候是每个线程有自己的form,但是同样会抛出AccessViolationException异常

    Time_tick方法最后重新调用了Begin(),所以会一直循环下去直到最后

    2012年7月16日 10:04
  • 我大概试了一下,总是在document.body.InnerHTML这句出的错。document是好的,document.body是空。

    不知道怎么回事,所以把我的代码帖上来,你看看,能不能修改修改重现你的问题。maxThreadCount = 15.

    googlemap.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    
    namespace ForumMultiThreadWebBrowser
    {
        class GoogleMap
        {
            public GoogleMap()
            {
                this.lockHtmlContentQueue = new Object();
                this.lockMemory = new Object();
                this.lockProgram = new Object();
    
                this.htmlContentQueue = new Queue<string>();
            }
    
            public void Init()                                        //每个线程有自己的form和WebBrowser                                                                                          
            {
                lock (lockMemory)
                {
                    this.form = new Form();
                    this.webBrowser = new WebBrowser();
                    this.form.Controls.Add(webBrowser);
                }
                form.WindowState = FormWindowState.Minimized;
                form.Visible = false;
                form.ShowInTaskbar = false;
                this.webBrowser.ScriptErrorsSuppressed = true;
                this.webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
    
                Begin();
            }
    
            public void Begin()
            {
    
                lock (lockProgram)
                {
                    int cnt = Program.shopListOffset++;
                    if (cnt >= Program.totalCount)
                    {
                        Console.WriteLine("Finish!");
                        System.Threading.Thread.CurrentThread.Abort();
                    }
                    shopInfo = Program.shopInfoQueue.Dequeue();                                 //从队列中取URL
                }
    
                this.webBrowser.Navigate(getUrl(shopInfo));
                if (form.Visible == false)
                    form.ShowDialog();
            }
    
            void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                if (((WebBrowser)sender).ReadyState < WebBrowserReadyState.Complete)
                    return;
                waitSomeTime();
            }
    
            public void waitSomeTime()                                        //需要在页面加载完成后等待2秒才能取到要取的内容
            {
    
                timer = new System.Windows.Forms.Timer();
    
                timer.Interval = 2000; //2秒啓動
                timer.Tick += new EventHandler(Timer_Tick);
                timer.Start();
            }
            private void Timer_Tick(object sender, EventArgs e)
            {
                lock (lockHtmlContentQueue)
                {
                    System.Windows.Forms.HtmlDocument document = this.webBrowser.Document;        //这句出错
                    Program.shopInfoQueue.Enqueue(shopInfo);
                    this.htmlContentQueue.Enqueue(document.Body.InnerHtml);
    
                }
    
                Begin();
            }
    
            private string getUrl(ShopInfo shopinfo)
            {
                return shopinfo.URL;
            }
    
            #region Fields
    
            private object lockMemory;
            private object lockProgram;
            private object lockHtmlContentQueue;
    
            private WebBrowser webBrowser;
            private Form form;
            private Timer timer;
            private ShopInfo shopInfo;
            private Queue<string> htmlContentQueue;
    
            #endregion
    
        }
    }
    

    ShopInfo.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ForumMultiThreadWebBrowser
    {
        class ShopInfo
        {
            public ShopInfo(string url)
            {
                this.Url = url;
            }
    
            public string URL { get { return this.Url; } }
    
            private string Url;
        }
    }
    

    Program.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    
    namespace ForumMultiThreadWebBrowser
    {
        class Program
        {
            static void Main(string[] args)
            {
                Program.shopListOffset = 0;
                Program.shopInfoQueue = new Queue<ShopInfo>();
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://bing.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://google.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://microsoft.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://cnn.com"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://facebook.com"));
                Program.totalCount = Program.shopInfoQueue.Count;
    
    
                int maxThreadCount = Int32.Parse(Console.ReadLine());
    
                System.Threading.Thread[] t = new Thread[maxThreadCount];
                GoogleMap[] gm = new GoogleMap[maxThreadCount];
    
    
                for (int i = 0; i < maxThreadCount; i++)
                {
                    gm[i] = new GoogleMap();
                    t[i] = new Thread(gm[i].Init);
                    t[i].SetApartmentState(System.Threading.ApartmentState.STA);
                    t[i].Start();
                }
    
            }
    
            public static int shopListOffset;
            public static int totalCount;
            public static Queue<ShopInfo> shopInfoQueue;
        }
    }
    

    2012年7月17日 6:30
  •             Program.shopInfoQueue.Enqueue(new ShopInfo("http://www.dianping.com/shop/5438066"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://www.dianping.com/shop/4227576"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://www.dianping.com/shop/1989367"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://www.dianping.com/shop/5646380"));
                Program.shopInfoQueue.Enqueue(new ShopInfo("http://www.dianping.com/shop/1990279"));

    你把url换成这些,然后数据量大一些,大概到5000条左右吧,应该就会出我说的那个错误了

    多谢指点了,嘿嘿

    2012年7月18日 10:38
  • 高手?找到问题所在了吗?

    2012年7月24日 2:28
  • 我不能重现你的问题,我总是遇到document.body为空的情况。也许和你遇到的问题是类同的,只是表现不一样。我打算调试一下我的问题,然后贴上来供你参考。
    2012年7月24日 7:10