IsNemoEqualTrue/monitor-table-change-with-sqltabledependency

No notification inner using sentence

ayams opened this issue · 3 comments

ayams commented

You have this example:
using (var dep = new SqlTableDependency(_con, "Customers", mapper: mapper));
{
dep.OnChanged += Changed;
dep.Start();

Console.WriteLine("Press a key to exit");
Console.ReadKey();

dep.Stop();
}

but it doesn't work if I use the sentence "using". If I set out the instance out of "using" it works. Why?

i cannot understend. can you explain better the problem?

ayams commented

you are using in the WRONG way.
to receive notifications, SqlTableDependency instance must be "live".
When the code goes out of the using statement, SqlTableDependency instance is DISPOSED.
In my example infact, there is a Console.ReadKey() to stop the current thread to goes out of the using statement.