日期:2014-05-17  浏览次数:20768 次

线程延时为啥使得数据访问又从头开始了那?求高手急救,明天就要交项目了。
我做了个异步下载AP,为保证同时有2个线程下载,做了线程延时,直接用thread.spleep会阻塞异步。如果到达2同时下载个就等待,值得检查到系统有1个或者0个的时候再次继续
队列中有1,2,3,4。下载完ID:1,2的,延时判断CheckOutOfMaxThread()通过再次运行,又从1开始了,为啥不从上次延时的3开始那?

调用代码如下
                        for (int i = 0; i < count_total;i++ )
                        {
                            pic_id = ApplicationCommon.IsInt(dt_gallery.Rows[i]["pic_id"].ToString());
                            pic_no = dt_gallery.Rows[i]["pic_no"].ToString();
                            user_account = dt_gallery.Rows[i]["user_account"].ToString();


                            if (CheckOutOfMaxThread())
                            {
                            #region  Gallery download

                     

                            #endregion
                            }
}


        /// <summary>
        /// if out of max thread then sleep 1 minute then check again
        /// </summary>
        /// <returns></returns>
        private bool CheckOutOfMaxThread()
        {