我要做一个WinForm程序,当我单击列表中的某一条记录的时候,WinForm自动加载显示与该条记录相关的数据信息,为了有更好的用户体验,我在WinForm程序加载相关数据的时候显示等待对话框,过程序相关代码如下:public void FillSbjForStudent()
{
if (bASStudentBindingSource.Current != null)
{
DataRowView dr = (DataRowView)this.bASStudentBindingSource.Current;
BASStudentManager manger = new BASStudentManager();
ThreadStart starter = delegate
{
manger.FillBASSbjForStudent(this.dsSbjForStudent.BASSbjForStudent, new Guid(dr["StudentID"].ToString()));
};
loading.Loading(starter);
}
}public class BASLoading
{
public static bool IsOpen = false; public void Loading(ThreadStart starter)
{
#region 加载数据动态效果
try
{
TBI.BaseUserControl.FrmLoading frm = new FrmLoading();
IsOpen = false; starter += delegate {
while (true)
{
if (IsOpen)
{
frm.Close();
break;
}
}
};
Thread th = new Thread(starter);
th.Start();
frm.ShowDialog();
}
catch(Exception ex)
{
}
#endregion
}
}运行的时候,偶尔会出现如题目所示的错误提示各位大牛,这个问题该怎么解决呢?
{
if (bASStudentBindingSource.Current != null)
{
DataRowView dr = (DataRowView)this.bASStudentBindingSource.Current;
BASStudentManager manger = new BASStudentManager();
ThreadStart starter = delegate
{
manger.FillBASSbjForStudent(this.dsSbjForStudent.BASSbjForStudent, new Guid(dr["StudentID"].ToString()));
};
loading.Loading(starter);
}
}public class BASLoading
{
public static bool IsOpen = false; public void Loading(ThreadStart starter)
{
#region 加载数据动态效果
try
{
TBI.BaseUserControl.FrmLoading frm = new FrmLoading();
IsOpen = false; starter += delegate {
while (true)
{
if (IsOpen)
{
frm.Close();
break;
}
}
};
Thread th = new Thread(starter);
th.Start();
frm.ShowDialog();
}
catch(Exception ex)
{
}
#endregion
}
}运行的时候,偶尔会出现如题目所示的错误提示各位大牛,这个问题该怎么解决呢?
private static readonly object lockder = new object();starter += delegate {
lock(locker)
{while (true)
{
if (IsOpen)
{
frm.Close();
break;
}
}
}
};