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

关于下载的问题
我有一个下载页面,但是现在同时只能一个人下载,就是如果有人在下载过程中,别人想下载就不行
代码如下,谁帮忙看看怎么改?

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //完成下载以后更新下载次数
            if (download())
            {
                int count = 0;
                System.IO.StreamReader srd;
                string file_path = Server.MapPath("~/count.txt");
                srd = System.IO.File.OpenText(file_path);
                while (srd.Peek() != -1)
                {
                    string str = srd.ReadLine();
                    count = int.Parse(str);

                }
                srd.Close();
                object obj = count;
                Application["count"] = obj;


                Application.Lock();
                int State = 0;
                State = (int)Application["count"];
                State += 1;
                obj = State;
                Application["count"] = obj;
                file_path = Server.MapPath("~/count.txt");
                System.IO.StreamWriter srw = new System.IO.StreamWriter(file_path, false);
                srw.WriteLine(State);
                srw.Close();
                Application.UnLock();
            }
        }
    }