Starting two listener in same app, Second one is not working
I have got triggers, service, queues, storedprocedures added as it has to be, but second trigger not firing, iam using latest code. thanks
static void Main(string[] args) { try {
SqlDependencyExNew sqlDependency = new SqlDependencyExNew(
connectionString: conx, databaseName: "db", tableName: "table", listenerType: NotificationTypes.Update, identity: 1);
sqlDependency.TableChanged += (o, e) => OnChange(o, e);
SqlDependencyExNew sqlDependency2 = new SqlDependencyExNew(
connectionString: conx, databaseName: "db", tableName: "table", listenerType: NotificationTypes.Update, identity: 2);
sqlDependency.TableChanged += (o, e) => OnChangeA(o, e);
sqlDependency.Start();
sqlDependency2.Start();
Console.WriteLine("______________Escuchando_______________");
Console.ReadKey();
sqlDependency.Stop();
sqlDependency2.Stop();
}
catch (Exception exp)
{
if (listener.Active == true)
{
listener.Stop();
}
if (listener2.Active == true)
{
listener2.Stop();
}
throw;
}
}
private static async void OnChangeA(object o, SqlDependencyExNew.TableChangedEventArgs e)
{
await SOMETHING(o, e);
}
private static Task<XElement> SOMETHING(object o, TableChangedEventArgs e)
{
var xxx = e.Data;
return Task.Run(() =>
{
return xxx;
});
}
private static async void OnChange(object o, SqlDependencyExNew.TableChangedEventArgs e)
{
await SOMETHING(o, e);
}
}
Are both table names the same?
different tables, i have tried all behaviours, insert, update etc. a surprising thing i discovered that after launching two triggers to two different tables in the same app i insist, trigger to table works good in which u make change first. second one got stuck as trigger is not working or responding. i have created a class to access ur code to make identity autoincrementable. i will post that class tomorrow. thanks for responding so quick. I appriciate.
Your code doesn't work as is. I made some adjustments and then it seems to work fine with both tables receiving updates.
Here is my revised gist for you including some test tables scripts