今天调试程序时遇到这个exception,网上查了下资料,遇到的人还不少,
后面带的数字还有不一样的,自己模拟了下,发现,在多线程下同时对表进行插入操作就会产生“5”的错误
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
private void button2_Click(object sender, EventArgs e)
{
Thread t1 = new Thread(new ThreadStart(update));
t1.IsBackground = true;
Thread t2 = new Thread(new ThreadStart(update));
t2.IsBackground = true;
t1.Start();
t2.Start();
}
private void update()
{
DataSet1.First_TableRow ftr = ftdt.NewFirst_TableRow();
ftr.name = "****";
ftr.phone = "123456";
ftr.rectime = DateTime.Now;
ftr.address = "address";
ftdt.AddFirst_TableRow(ftr);
}
多线程产生的异常,解决办法只能对这个方法进行下包装了,lock住,一个一个操作就ok了