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

.because it is being used by anothr process求解!该如何处理

2013-04-21 
...because it is being used by anothr process求解!!!最近用户不能访问站点,打开服务器一看,提示一个文

...because it is being used by anothr process求解!!!
最近用户不能访问站点,打开服务器一看,提示一个文本文件被一进程使用,无法访问。
在网上查了资料,说是读取的流没有关闭,但我的关闭了的呀!
而另一个站点采用了同一段代码,没有报过这样的错误!
唯一不同的是,报错的站点,访问的用户在日本。但也是同一个集团的,在同一个网络内的。

以下为两个站点的代码比较。

 protected void Page_Load(object sender, EventArgs e)
        {
            year =  DateTime.Now.Year.ToString();
            DirectoryInfo dirWeeks = new DirectoryInfo(@"C:\Inetpub\wwwroot\ProductionPlan" + year);
            weeks = dirWeeks.GetDirectories();
            selectedWeek = weeks[weeks.Length - 1].ToString().Substring(0, 2)+"W";//嵟岪堦廃
            lbWeek.Text = selectedWeek;//嵟岪堦廃
            if (!IsPostBack)
            {

              //  BindCombox();  
                WriteLog();
                InitLinkButton();               
                lbYear.Text = year;               
                lbWeek.Text = selectedWeek;
                lbKind.Text = ddlPlan.SelectedValue;               
            };
            
        }

        private void WriteLog()
        {
            StreamWriter sw;
            System.IO.Directory.CreateDirectory(@"C:\Information");
            sw = File.AppendText(@"C:\Information\logPH.txt");
            IPHostEntry host = Dns.GetHostEntry(GetClientIP());
            string MyHost = host.HostName;
            //  string Name=User.Identity.Name.ToString();
            sw.WriteLine("庡婘?崋丗" + MyHost + ",????丗" + DateTime.Now);
            //sw.WriteLine("庡婘?崋丗" + hname + ",梡?柤:" + Request.ServerVariables["LOGON_USER"] + "-----------" + DateTime.Now); 
            // sw.WriteLine("梡?柤:" + Request.ServerVariables["LOGON_USER"] + ",????丗" + DateTime.Now);         


            sw.Flush();
            sw.Close();
        }
        private string GetClientIP()
        {
            string result =
            HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (null == result || result == String.Empty)
            {
                result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }
            if (null == result || result == String.Empty)
            {
                result = HttpContext.Current.Request.UserHostName;
            }
            return result;
        }



------------------------------
protected void Page_Load(object sender, EventArgs e)
    {
        //string strhostname = System.Net.Dns.GetHostName();
        WriteLog();
        lbNotes.Text += GetMessage();
    }

    private void WriteLog()
    {
        StreamWriter sw;
        System.IO.Directory.CreateDirectory(@"C:\Information");
        sw=File.AppendText(@"C:\Information\log.txt"); 
        IPHostEntry host= Dns.GetHostEntry(GetClientIP());
        string MyHost = host.HostName;
      //  string Name=User.Identity.Name.ToString();
        sw.WriteLine("庡婘?崋丗" + MyHost +  ",????丗" + DateTime.Now); 
        //sw.WriteLine("庡婘?崋丗" + hname + ",梡?柤:" + Request.ServerVariables["LOGON_USER"] + "-----------" + DateTime.Now); 
      // sw.WriteLine("梡?柤:" + Request.ServerVariables["LOGON_USER"] + ",????丗" + DateTime.Now);         
        sw.Flush();
        sw.Close();
    }
    private string GetClientIP()
    {
        string result =
        HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];


        if (null == result || result == String.Empty)
        {
            result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
        }
        if (null == result || result == String.Empty)
        {
            result = HttpContext.Current.Request.UserHostName;
        }
        return result;
    }



[解决办法]
并发访问的情况有处理吗?

热点排行