zoukankan      html  css  js  c++  java
  • NHibernate multithreading issue (多线程问题)

          int limitTimes;
                int.TryParse(ConfigurationManager.AppSettings["LimitTimes"], out limitTimes);
                var redoPurchaseEntityList =
                  this.redoPurchaseEntityRepository.FindByExpression(p => p.SendNumber < limitTimes).ToList();
                if (redoPurchaseEntityList.Count == 0)
                {
                    return;
                }
                Parallel.ForEach(
                    this.redoPurchaseProvideList,
                    redoPurchase =>
                    {
                        var task = new Task(() => redoPurchase.RedoPurchase(redoPurchaseEntityList));
                        task.StartAndContinueWith();
                    });
    

    上面代码主要是从数据库中查询出一个表的list集合然后多线程并行查找同一个list,会得到一个错误信息

    There is already an open DataReader associated with this Command which must be closed first.
    at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)

    因为用的是一个session,导致读取错误多线程不可互用同一个session.

    可参考 http://stackoverflow.com/questions/7886260/nhibernate-multi-threading-issue  

  • 相关阅读:
    布局
    面向对象....(概况)
    下拉城市列表
    下拉列表
    内容窗体
    《面向对象》-继承
    《面向对象》--类
    《面向对象》第一讲
    常用的正则表达式
    正则表达式
  • 原文地址:https://www.cnblogs.com/mmnyjq/p/2816369.html
Copyright © 2011-2022 走看看