首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

ThreadPool的有关问题,大家来帮看看

2013-02-19 
ThreadPool的问题,大家来帮看看部分代码//初始化线程池数量ThreadPool.SetMaxThreads(50, 50)ThreadPool.

ThreadPool的问题,大家来帮看看
部分代码


//初始化线程池数量
ThreadPool.SetMaxThreads(50, 50);
ThreadPool.SetMinThreads(20, 20);

//这里是增加线程 这些个for循环是在一个方法里 方法又是让timer定时5秒调用一次的
           for (int j = 0; j < geturlList.Count; j++)
           {
               object o = geturlList[j];
               ThreadPool.QueueUserWorkItem(sendMyData, o);
            }
            for (int j = 0; j < this.geturlListUp.Count; j++)
            {
                object o = geturlListUp[j];
                ThreadPool.QueueUserWorkItem(sendMyData, o);
            }

            for (int x = 0; x < posturlList.Count; x++)
            {
                string[] tmpstrs = { posturlList[x], refurlList[x], paramList[x] };
                object o = tmpstrs;
                ThreadPool.QueueUserWorkItem(sendMyDataTwo, o);
            }
            for (int x = 0; x < this.posturlListUp.Count; x++)
            {
                string[] tmpstrs = { posturlListUp[x], refurlListUp[x], paramListUp[x] };
                object o = tmpstrs;
                ThreadPool.QueueUserWorkItem(sendMyDataTwo, o);
            }

    //这是线程调用的一个方法里边的部分内容
            try
            {
                lock (myparam)//这里的myparam就是传过来的参数
                {
                    string geturlt = myparam.ToString();

                    if (tureVal)//验证
                    {
                        WebRequest wr = WebRequest.Create(geturlt);


                        wr.Timeout = 15000;//超时
                        wr.GetResponse().GetResponseStream();
                    }
                }

            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
                //Console.WriteLine(geturlt);
                return;
            }

    //线程调用的另一个方法差不多一样 里边使用了 HttpWebRequest和HttpWebResponse 也是try catch 包     着 lock参数
            



不知道为啥 开始执行能发送和接收数据  后边1 2分钟吧 线程全是等待 我设置的 Timeout = 15000; 要说如果超时了应当线程也算执行完了吧 应当可以执行下边的线程了吧 但等好久都不执行 
以前没用过多线程池 直接for循环new新的线程  有时候会出现内存问题 线程池是第一次用  请高手们帮着讲讲
[解决办法]
如果线程没有死锁,wr.Timeout = 15000;后加 wr.Proxy = null;

热点排行