/// dep监听表变化
///
private void oracleLisentDep()
{
if (oracleDep == null || !oracleDep.IsEnabled)
{
OracleCommand tmpCMD = new OracleCommand("select * from kkk", oracleConn);
///oracleDep (cmd,是否一次后就移除注册,注册持续多长时间0为永久,True是保存在硬盘False是在内存数据库服务器重启后就丢失了);
oracleDep = new OracleDependency(tmpCMD, true, 0, true);
oracleDep.OnChange += new OnChangeEventHandler(OnNotificaton);
try
{
OracleDataReader odr = tmpCMD.ExecuteReader();// 就是从这句开始死掉!!!!!!
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
}
}
///
/// 当指定的表发生变化,指定触发的事件
///
private void OnNotificaton(object src, OracleNotificationEventArgs arg)
{
//可以从arg.Details中获得通知的具体信息,比如变化数据的RowId
try
{
DataTable dt = arg.Details;
MessageBox.Show(dt.Columns[0].ToString());
}
catch (Exception ex) { MessageBox.Show("错误信息"+ ex.ToString()); }
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try
{ //退出程序时清除所有的注册
oracleDep.RemoveRegistration(oracleConn);
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
e.Cancel = false;
}
第一次调试是OK的