PS: I guess I have posted in the wrong forum, I don't know how to move this question to "OPC-ALARM-EVENTS" Forum, Can any moderator please move it over there.
Hi,
In one of my projects, I have to keep a track of all active events in a DataGrid,
The catch here is if the same event happens after lets say 10 seconds again,then only display in the Grid
here is my Source Code...
private readonly DataTable _alarms = new DataTable("Alarms");
private int _handle;
public AlarmControl()
{
InitializeComponent();
_dataGridView.DataSource = _alarms;
}
private void AlarmControl_Load(object sender, EventArgs e)
{
easyAEClient1.Notification += OnNotification;
_handle = easyAEClient1.SubscribeEvents("", "MyServerName", 100);
}
private void RefreshBtn_Click(object sender, EventArgs e)
{
_alarms.Rows.Clear();
easyAEClient1.RefreshEventSubscription(_handle);
}
private void ExitBtn_Click(object sender, EventArgs e)
{
easyAEClient1.UnsubscribeAllEvents();
}
private void OnNotification(object sender, EasyAENotificationEventArgs args)
{
if (args.Exception != null || args.Event == null)
return;
if(args.Event.Active)
{
var row = _alarms.NewRow();
row["Time"] = args.Event.Time;
row["Active"] = args.Event.Active;
row["Condition"] = args.Event.ConditionName;
row["Severity"] = args.Event.Severity;
row["Message"] = args.Event.Message;
// Here I want a 10 seconds Timer and check if the same Event Still exists,only then Insert in DataGrid
_alarms.Rows.InsertAt(row,0);
}
}
One way I can think is the moment I get this Event Notification, unsubscribe from the event and after 10 seconds call RefreshEventSubscription , if I get same Event Notification, then only add to my Grid.
However I am not sure if this the best way to achieve my requirement, What could be the the best way to achieve it?