Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting two listener in same app, Second one is not working #45

Open
NadzChoudhry opened this issue Jun 22, 2017 · 3 comments
Open

Starting two listener in same app, Second one is not working #45

NadzChoudhry opened this issue Jun 22, 2017 · 3 comments

Comments

@NadzChoudhry
Copy link

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);
    }

}

@Siliconrob
Copy link
Contributor

Are both table names the same?

@NadzChoudhry
Copy link
Author

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.

@Siliconrob
Copy link
Contributor

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

⚡️ SqlDependencyEx - TableListener Example ⚡️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants