当前位置:编程学习 > C#/ASP.NET >>

c# WebBrowser 下报错 尝试读取或写入受保护的内存。这通常指示其他内存已损坏

有这样一个需求,数据库表中主要字段为keyword,productID,利用keyword查找productID。

从数据库中读取数据后,利用线程把相同关键字的productID一起查找

void AA()

{

//查找数据库

for (int i = 0; i < keywordList.Count; i++)

Dictionary<int, object> keywordSearch = new Dictionary<int, object>();
                keywordSearch.Add(0, keywordList[i]);//关键字
                keywordSearch.Add(1, searchList[i].ProductIDList );                ParameterizedThreadStart parame = new ParameterizedThreadStart(GoSearch);
                Thread threadSearch = new Thread(parame);
                threadSearch.IsBackground = true;
                threadSearch.SetApartmentState(System.Threading.ApartmentState.STA);
                threadSearch.Start(keywordSearch);
                Thread.Sleep(10 * 1000);

 }

void GoSearch(  object  arrayDic)//productIDList为商品ID

{

Dictionary<int, object> dic = (Dictionary<int, object>)arrayDic;
 string keyWord = (string)dic[0];//关键字

Dictionary<decimal, string> productIDList =(Dictionary<decimal, string>)dic[1];//

string page="";//网址

WebBrowser web = new WebBrowser();

web.Navigate(page);

 int pageID = 1;//当前页

while(productIDList.Keys.Count > 0)

{

GC.Collect();

if (web.IsDisposed)
{
      productIDList.Clear();
       break;
}

while (web.ReadyState < WebBrowserReadyState.Complete)
                        Application.DoEvents();

//查找productID 

//如果找到productID,则从productIDList中删除

//查找下一页的链接,并返回下一页的页数

page="下一页的网址";

if (pageID > 100)//超出100页则停止
 {
      productIDList.Clear();
       web.Dispose();
        break;
 }

web.Navigate(page);

}

}

代码大概如上所示,但是现在出现问题,

请问各位大侠,这个问题如何解决

补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,