本帖最后由 Net85 于 2010-09-18 08:44:54 编辑

解决方案 »

  1.   

    如果你的网速不够的话用多线程也没用.
    当然如果网速够的话可用多线程,至于你说的session为空的问题,要具体分析.你可把session做为一个参数传给线程.
      

  2.   

    网速是够的。我在网上查了查,似乎只有多线程能提高发送速度。你说的把session作为参数传递,是一个解决方法,我开始也有想到,但是。,我的整个网站都是用session在传递,特别是还牵扯到把session值,写入第三方提供的DLL,所以我没法把session作为参数传递,这样不仅需要改以前的大量代码,而且容易造成调用DLL出错。两个线程都用同样的session,有有没有办法,避免不出错?
      

  3.   


      protected void FirstThread(M_Leds ML,B_Leds BL, string sendResult, int SelectCount)
        {
           
            int led_id = ML.led_id;//屏ID
            int cardtype_id = ML.cardtype_id;//屏类型ID
            string led_name = ML.led_name;//屏名称
            string led_ip = ML.led_ip;//屏IP        HttpContext.Current.Session["ScreenWidth"] = ML.led_width;//屏宽//出错在这,为将对象引用到实例
            HttpContext.Current.Session["ScreenHeight"] = ML.led_height;//屏高
            HttpContext.Current.Session["Led_istime"] = ML.led_istime;//屏幕时间显示
            HttpContext.Current.Session["Default_size"] = Convert.ToInt32(ML.led_default_fontsize);//默认字号
            HttpContext.Current.Session["Min_size"] = Convert.ToInt32(ML.led_min_fontsize);//最小字号
            if (Convert.ToInt32(HttpContext.Current.Session["ScreenHeight"]) < 96)
            {
                HttpContext.Current.Session["top_time"] = 16;
            }        else
            {
                HttpContext.Current.Session["top_time"] = 24;
            }
            string Send_Result = "";
            StringBuilder Send_Resultt = new StringBuilder("");
            Send_Resultt.Append(sendResult);
                      Send_Result = send_swith(cardtype_id, led_id, led_ip); //这里的方法调用第三方DLL,方法很长,包含的有多个session.
                //修改最后一次接收日期
                if (Send_Result == define.SEND_SUCC)
                {
                    ML.led_lastupdatetime = DateTime.Now.ToString();
                    BL.Update(ML);
                    Send_Resultt.Append(Send_Result + ",");
                    Send_Result = ",,,";
                }
                else
                {
                    Send_Resultt.Append(Send_Result + ",");
                }            //写发送记录
                using (StreamWriter sw = new StreamWriter(Server.MapPath("..\\history\\SendHistory.txt"), false, System.Text.Encoding.UTF8))
                {
                    sw.Write(Send_Resultt);
                    sw.Close();
                } }谢谢
      

  4.   

    HttpContext.Current.Session["ScreenWidth"] = ML.led_width;//屏宽 出错在这,给session赋值时,未将对象引用到实例
      

  5.   

    在线程中这样是取不到session的.HttpContext.Current就已经不存在了,必须通过其他方法来.如传参数,或全局变量(注意不同用户的划分)
      

  6.   

    是因为两个线程同时给Session赋值了
    用SESSIONI的时候用LOCK锁住
      

  7.   


    恩,网上查的时候也是这样解释的。我刚接触线程,还不是很懂。请问那用LOCK锁住是什么意思?详细说下吧,谢谢。
      

  8.   

    注意不同用户的划分这个确实是,谢谢你的提醒。如果我最后放弃用session的话,我会用这个的。