多个线程同时访问数据库:注意红色字体
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StudentTest;
using System.Threading;
using Domain;
using NHibernate;
namespace StudentTest
{
class Program
{
static Thread[] thr;
static void Main(string[] args)
{
// int length = 200;
Program p = new Program();
thr = new Thread[100];
for (int i = 0; i < thr.Length; i++)
{
thr[i] = new Thread(new ThreadStart(p.Read));
thr[i].IsBackground = true;
thr[i].Start();
//Thread.Sleep(2000);
}
Console.ReadKey();
}
IStudentDao stuDao = new StudentDao();
public void Non()
{
stuDao.Save(new Student { ID = new Guid(), Name = "tyu" });
}
IStudentDao stuDao1 = new StudentDao();
public void Read()
{
Student stu1 = new Student();
IList<Student> stu = stuDao1.LoadAll();
foreach (var item in stu)
{
Console.WriteLine(item.Name);
}
}
}
}