public void SendNotification()
{
string message = "";
string constr = "xxxxxxxxxxxxx";
using (SqlConnection connection = new SqlConnection(constr))
{
string query = "XXXXXXXXXX";
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Notification = null;
SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_Onchange);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
message = message + "<br>" + reader.GetSqlValue(0);
notifications_count = notifications_count + 1;
_IsUnread = 1;
}
}
}
}
private void dependency_Onchange(object sender, SqlNotificationEventArgs e)
{
if (e.Type == SqlNotificationType.Change)
{
SendNotification();
}
}
so dass der obige Code funktioniert prima (jedes Mal, Brennen), wenn if (e.Type == SqlNotificationType.Change)
verwenden, aber das ist das Problem, wenn ich die if (e.Info.ToString() == "Insert")
bin mit innen dependency_OnChange wiedependency_OnChange Verfahren Brennen nur einmal, wenn sqlnotificationargs.info statt sqlnotificationargs.type
private void dependency_Onchange(object sender, SqlNotificationEventArgs e)
{
if (e.Type == SqlNotificationType.Change)
{
if (e.Info.ToString() == "Insert")
{
SendNotification();
}
}
}
wird die Methode nur einmal ausgelöst.