我有一个Windows窗体,可以订阅一些事件。
FormClosing += save;
EncompassApplication.CurrentLoan.BeforeCommit += save;
这是在新线程中打开的表单。
void save(object sender, EventArgs e)
{
updateItems();
}
我的save方法基本上只是将表单的当前状态保存到数据库中。
我的表单可以很好地保存在FormClosing上,但是EncompassApplication.CurrentLoan.BeforeCommit来自运行在不同线程中的应用程序,并且在触发该事件时,它无法正常工作。几乎就像我为此事件的save方法一样,正在获取表单的空白实例,并覆盖表单中填充的所有信息。
如何编写我的代码,以便EncompassApplication.CurrentLoan.BeforeCommit获取表单的当前版本以保存到数据库?
表单构造器
public CheckList(bool canEdit)
{
this.canEdit = canEdit;
FormClosing += save;
FormClosing += updateStatus;
EncompassApplication.CurrentLoan.BeforeCommit += save;
password.MakeReadOnly();
SqlCredential sqlCred = new SqlCredential(username, password);
SqlConnection connection = new SqlConnection(connectionString, sqlCred);
connection.Open();
addHeaders(connection);
populateItems(connection);
connection.Close();
drawFooter();
isOpen = true;
InitializeComponent();
}