notification not working when an IF-statement return FALSE

Aug 9, 2016 at 3:40 PM
Hi!
im new using Table Dependency and im work with the basic example that shows in the video tutorial..i used a console application so when recieve a notification for a change trigger a buttom that can send an email if you want it..
I filter the data type in the table, if the data type is not what I need for the button will not be displayed ..
the problem is that when the data type is not the expected and the if statement is 'false' the change messages no longer appear and have to restart the application ..me like to know I'm doing wrong and if you can help me..

here;s the code



static void tableDependency_OnChanged(object sender, RecordChangedEventArgs<costumer> e)
    {
        Correo2 frm = new Correo2();
        SINO frm1 = new SINO();
      Console.WriteLine(Environment.NewLine);
        if (e.ChangeType == ChangeType.None)
        {
            var changedEntity = e.Entity;
            frm1.tipo = changedEntity.surname;
            frm1.docu = changedEntity.name;
          Console.WriteLine("DML operacion : " + e.ChangeType);
            Console.WriteLine("ID>: " + changedEntity.id);
            Console.WriteLine("name>: " + changedEntity.name);
            Console.WriteLine("surname>: " + changedEntity.surname);
            Console.WriteLine(Environment.NewLine);


          if (MessageBox.Show("Send the mail?", "ok", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
             frm.ShowDialog();                

            }

        }
    }

Coordinator
Aug 9, 2016 at 7:19 PM
Hi...I do not understand very well.

"the problem is that when the data type is not the expected and the if statement is 'false'"

Can you explain your problem better ? Which if statement ?

bye
Aug 9, 2016 at 7:48 PM
Sorry!!!,

I'll explain better..


I tried the basic example and it worked well but when I put a condition " IF. { } . ELSE {}" ..if the condition is true runs perfectly , but if the condition is false stops sending notifications of change in database.. only when DialogResult.Yes is true then keep sending notifications.. when it enters the ' ELSE' when it is false then stops sending notifications


if (MessageBox.Show("Send the mail?", "ok", MessageBoxButtons.YesNo) == DialogResult.Yes) // only when DialogResult.Yes is true then keep sending notifications..
        {
         frm.ShowDialog();                

        }
else
{
// when it enters the ' ELSE' when it is false then stops sending notifications
//other code...
}
Coordinator
Aug 9, 2016 at 7:58 PM
Ok...Understood.

I have an idea but only you can test it because I have no idea about what happen in the ELSE block.

May be you can have the same issue in case the user does not chose YES or NO immediatelly: Assuming that the message box stay opened for 5 minutes, you will not receive any more notification. This is because C# event are sincronously. SqlTableDependency remains blocked until the tableDependency_OnChanged event haldler is in execution. So, after 3 minutes, the SqlTableDependency's watch dog starts and remove all object in DB.

So, if the time spent from the ELSE block takes more than 3 minutes --> no any more notification.

Check if the trigger generated from SqlTableDependency is still present whan you do not receive any more notifications.

Let me know.
Aug 9, 2016 at 8:40 PM
hi,

look what im trying to do ..
I have three types of documents, ' F' , ' D ', ' C ' in a table , so what need is when the document is type ' C ' then run the code in the IF block otherwise enter in de ELSE BLOCK and keep waiting notifications of the table in sql server... in the ELSE BLOCK I have nothing yet ,..

I fully understand the case elapsed time, only in this case does not take even 10 seconds .. is just choose Yes or No, if Yes then displays a window to mail the document type "C" otherwise if you choose "no" does not show anything and continue waiting until next Insert . and repeat the operation over and over again.


You are right when I choose "No" and enter the ELSE block and do nothingc[no code in the block ] , the trigger generated from SqlTableDependency is stopped and the session is disconnects..


how could deal with the standby time when the user is doing nothing?

Thanks in advance for your time..
Coordinator
Aug 11, 2016 at 7:44 PM
"how could deal with the standby time when the user is doing nothing? "

In the same thread is not possible. Sorry