首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

该对象现阶段正在其它地方使用

2012-11-09 
该对象当前正在其它地方使用我要做一个WinForm程序,当我单击列表中的某一条记录的时候,WinForm自动加载显

该对象当前正在其它地方使用
我要做一个WinForm程序,当我单击列表中的某一条记录的时候,WinForm自动加载显示与该条记录相关的数据信息,为了有更好的用户体验,我在WinForm程序加载相关数据的时候显示等待对话框,过程序相关代码如下:

C# code
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        }    }


运行的时候,偶尔会出现如题目所示的错误提示

各位大牛,这个问题该怎么解决呢?

[解决办法]
对象没有关闭
[解决办法]
starter中做什么了,报错时出现在哪里,线程中有没有加锁,造成访问冲突
[解决办法]
声明一个静态变量:
private static readonly object lockder = new object();

starter += delegate {
lock(locker)
{while (true)
{

if (IsOpen)
{
frm.Close();
break;
}

}
}
};

热点排行