WPF C# HTMLDocument variables automatically updates












1















So I am trying to compare two HTMLDocuments to see if there are any changes in the website using a DispatchTimer().



Here is my code:



    HTMLDocument lastDoc;

public void startTimer()
{
lastDoc = (HTMLDocument)Form.RosterBrowser.Document;

DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += dispatcherTimer_Tick;
dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
var thisDoc = (HTMLDocument)Form.RosterBrowser.Document;
LogTextBlockControl.Text += "DOCUMENT THIS: " + thisDoc.getElementById("groupList").innerText.Length.ToString();
LogTextBlockControl.Text += "DOCUMENT LAST: " + lastDoc.getElementById("groupList").innerText.Length.ToString();
}


As you can see: When the times starts for the first time I get the HTMLDocument and store it in lastDoc. Then, every 2 seconds, I get another HTMLDocument variable and I store it in thisDoc. Now, I print the length of a certain element every 2 seconds to see if anything has changed inside this element.



When the program first starts, they both print the same number which is normal since they both got the same HTMLDocument. But lets say I change something in the groupList element. You'd think the length of the thisDoc variable would change. Well it does, but so does the length of lastDoc. This is where the problem occurs.



Whenever an element changes, thisDoc gets updated and prints the length of the changed element but lastDoc gets updated as well and starts printing the same length. This is not what I want since now I can't compare the two to fire a function. I only call startTimer() once in the entire program and I never change lastDoc, it seems to change on itself. I have been sitting on this problem for a day now, I hope someone can help me out.










share|improve this question





























    1















    So I am trying to compare two HTMLDocuments to see if there are any changes in the website using a DispatchTimer().



    Here is my code:



        HTMLDocument lastDoc;

    public void startTimer()
    {
    lastDoc = (HTMLDocument)Form.RosterBrowser.Document;

    DispatcherTimer dispatcherTimer = new DispatcherTimer();
    dispatcherTimer.Tick += dispatcherTimer_Tick;
    dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
    dispatcherTimer.Start();
    }
    private void dispatcherTimer_Tick(object sender, EventArgs e)
    {
    var thisDoc = (HTMLDocument)Form.RosterBrowser.Document;
    LogTextBlockControl.Text += "DOCUMENT THIS: " + thisDoc.getElementById("groupList").innerText.Length.ToString();
    LogTextBlockControl.Text += "DOCUMENT LAST: " + lastDoc.getElementById("groupList").innerText.Length.ToString();
    }


    As you can see: When the times starts for the first time I get the HTMLDocument and store it in lastDoc. Then, every 2 seconds, I get another HTMLDocument variable and I store it in thisDoc. Now, I print the length of a certain element every 2 seconds to see if anything has changed inside this element.



    When the program first starts, they both print the same number which is normal since they both got the same HTMLDocument. But lets say I change something in the groupList element. You'd think the length of the thisDoc variable would change. Well it does, but so does the length of lastDoc. This is where the problem occurs.



    Whenever an element changes, thisDoc gets updated and prints the length of the changed element but lastDoc gets updated as well and starts printing the same length. This is not what I want since now I can't compare the two to fire a function. I only call startTimer() once in the entire program and I never change lastDoc, it seems to change on itself. I have been sitting on this problem for a day now, I hope someone can help me out.










    share|improve this question



























      1












      1








      1








      So I am trying to compare two HTMLDocuments to see if there are any changes in the website using a DispatchTimer().



      Here is my code:



          HTMLDocument lastDoc;

      public void startTimer()
      {
      lastDoc = (HTMLDocument)Form.RosterBrowser.Document;

      DispatcherTimer dispatcherTimer = new DispatcherTimer();
      dispatcherTimer.Tick += dispatcherTimer_Tick;
      dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
      dispatcherTimer.Start();
      }
      private void dispatcherTimer_Tick(object sender, EventArgs e)
      {
      var thisDoc = (HTMLDocument)Form.RosterBrowser.Document;
      LogTextBlockControl.Text += "DOCUMENT THIS: " + thisDoc.getElementById("groupList").innerText.Length.ToString();
      LogTextBlockControl.Text += "DOCUMENT LAST: " + lastDoc.getElementById("groupList").innerText.Length.ToString();
      }


      As you can see: When the times starts for the first time I get the HTMLDocument and store it in lastDoc. Then, every 2 seconds, I get another HTMLDocument variable and I store it in thisDoc. Now, I print the length of a certain element every 2 seconds to see if anything has changed inside this element.



      When the program first starts, they both print the same number which is normal since they both got the same HTMLDocument. But lets say I change something in the groupList element. You'd think the length of the thisDoc variable would change. Well it does, but so does the length of lastDoc. This is where the problem occurs.



      Whenever an element changes, thisDoc gets updated and prints the length of the changed element but lastDoc gets updated as well and starts printing the same length. This is not what I want since now I can't compare the two to fire a function. I only call startTimer() once in the entire program and I never change lastDoc, it seems to change on itself. I have been sitting on this problem for a day now, I hope someone can help me out.










      share|improve this question
















      So I am trying to compare two HTMLDocuments to see if there are any changes in the website using a DispatchTimer().



      Here is my code:



          HTMLDocument lastDoc;

      public void startTimer()
      {
      lastDoc = (HTMLDocument)Form.RosterBrowser.Document;

      DispatcherTimer dispatcherTimer = new DispatcherTimer();
      dispatcherTimer.Tick += dispatcherTimer_Tick;
      dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
      dispatcherTimer.Start();
      }
      private void dispatcherTimer_Tick(object sender, EventArgs e)
      {
      var thisDoc = (HTMLDocument)Form.RosterBrowser.Document;
      LogTextBlockControl.Text += "DOCUMENT THIS: " + thisDoc.getElementById("groupList").innerText.Length.ToString();
      LogTextBlockControl.Text += "DOCUMENT LAST: " + lastDoc.getElementById("groupList").innerText.Length.ToString();
      }


      As you can see: When the times starts for the first time I get the HTMLDocument and store it in lastDoc. Then, every 2 seconds, I get another HTMLDocument variable and I store it in thisDoc. Now, I print the length of a certain element every 2 seconds to see if anything has changed inside this element.



      When the program first starts, they both print the same number which is normal since they both got the same HTMLDocument. But lets say I change something in the groupList element. You'd think the length of the thisDoc variable would change. Well it does, but so does the length of lastDoc. This is where the problem occurs.



      Whenever an element changes, thisDoc gets updated and prints the length of the changed element but lastDoc gets updated as well and starts printing the same length. This is not what I want since now I can't compare the two to fire a function. I only call startTimer() once in the entire program and I never change lastDoc, it seems to change on itself. I have been sitting on this problem for a day now, I hope someone can help me out.







      c# wpf wpf-controls mshtml






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 29 '18 at 8:22









      Lennart

      6,171125266




      6,171125266










      asked Nov 28 '18 at 22:06









      uRThowuRThow

      175




      175
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Form.RosterBrowser.Document returns a reference to the browser Document, so lastDoc and thisDoc are two references pointing to the same HTMLDocument object which sits somewhere on the memory heap.



          Instead you should store the value you are monitoring.

          You'd better monitor the text itself and not only its length as the text can be changed but keeping the same length.



          string lastText;

          private string GroupListText => ((HTMLDocument)Form.RosterBrowser.Document).getElementById("groupList").innerText;

          public void startTimer()
          {
          lastText = GroupListText;

          DispatcherTimer dispatcherTimer = new DispatcherTimer();
          dispatcherTimer.Tick += dispatcherTimer_Tick;
          dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
          dispatcherTimer.Start();
          }

          private void dispatcherTimer_Tick(object sender, EventArgs e)
          {
          var thisText = GroupListText;
          LogTextBlockControl.Text += "DOCUMENT THIS: " + thisText.Length.ToString();
          LogTextBlockControl.Text += "DOCUMENT LAST: " + lastText.Length.ToString();
          }


          I've used a property GroupListText to avoid duplicating the text lookup expression.






          share|improve this answer
























          • Works like a charm. I totally forgot about the stack and heap... Thankyou for the quick answer!

            – uRThow
            Nov 29 '18 at 5:54











          • I'm glad it works. :)

            – Pragmateek
            Nov 29 '18 at 10:54












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53528840%2fwpf-c-sharp-htmldocument-variables-automatically-updates%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Form.RosterBrowser.Document returns a reference to the browser Document, so lastDoc and thisDoc are two references pointing to the same HTMLDocument object which sits somewhere on the memory heap.



          Instead you should store the value you are monitoring.

          You'd better monitor the text itself and not only its length as the text can be changed but keeping the same length.



          string lastText;

          private string GroupListText => ((HTMLDocument)Form.RosterBrowser.Document).getElementById("groupList").innerText;

          public void startTimer()
          {
          lastText = GroupListText;

          DispatcherTimer dispatcherTimer = new DispatcherTimer();
          dispatcherTimer.Tick += dispatcherTimer_Tick;
          dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
          dispatcherTimer.Start();
          }

          private void dispatcherTimer_Tick(object sender, EventArgs e)
          {
          var thisText = GroupListText;
          LogTextBlockControl.Text += "DOCUMENT THIS: " + thisText.Length.ToString();
          LogTextBlockControl.Text += "DOCUMENT LAST: " + lastText.Length.ToString();
          }


          I've used a property GroupListText to avoid duplicating the text lookup expression.






          share|improve this answer
























          • Works like a charm. I totally forgot about the stack and heap... Thankyou for the quick answer!

            – uRThow
            Nov 29 '18 at 5:54











          • I'm glad it works. :)

            – Pragmateek
            Nov 29 '18 at 10:54
















          0














          Form.RosterBrowser.Document returns a reference to the browser Document, so lastDoc and thisDoc are two references pointing to the same HTMLDocument object which sits somewhere on the memory heap.



          Instead you should store the value you are monitoring.

          You'd better monitor the text itself and not only its length as the text can be changed but keeping the same length.



          string lastText;

          private string GroupListText => ((HTMLDocument)Form.RosterBrowser.Document).getElementById("groupList").innerText;

          public void startTimer()
          {
          lastText = GroupListText;

          DispatcherTimer dispatcherTimer = new DispatcherTimer();
          dispatcherTimer.Tick += dispatcherTimer_Tick;
          dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
          dispatcherTimer.Start();
          }

          private void dispatcherTimer_Tick(object sender, EventArgs e)
          {
          var thisText = GroupListText;
          LogTextBlockControl.Text += "DOCUMENT THIS: " + thisText.Length.ToString();
          LogTextBlockControl.Text += "DOCUMENT LAST: " + lastText.Length.ToString();
          }


          I've used a property GroupListText to avoid duplicating the text lookup expression.






          share|improve this answer
























          • Works like a charm. I totally forgot about the stack and heap... Thankyou for the quick answer!

            – uRThow
            Nov 29 '18 at 5:54











          • I'm glad it works. :)

            – Pragmateek
            Nov 29 '18 at 10:54














          0












          0








          0







          Form.RosterBrowser.Document returns a reference to the browser Document, so lastDoc and thisDoc are two references pointing to the same HTMLDocument object which sits somewhere on the memory heap.



          Instead you should store the value you are monitoring.

          You'd better monitor the text itself and not only its length as the text can be changed but keeping the same length.



          string lastText;

          private string GroupListText => ((HTMLDocument)Form.RosterBrowser.Document).getElementById("groupList").innerText;

          public void startTimer()
          {
          lastText = GroupListText;

          DispatcherTimer dispatcherTimer = new DispatcherTimer();
          dispatcherTimer.Tick += dispatcherTimer_Tick;
          dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
          dispatcherTimer.Start();
          }

          private void dispatcherTimer_Tick(object sender, EventArgs e)
          {
          var thisText = GroupListText;
          LogTextBlockControl.Text += "DOCUMENT THIS: " + thisText.Length.ToString();
          LogTextBlockControl.Text += "DOCUMENT LAST: " + lastText.Length.ToString();
          }


          I've used a property GroupListText to avoid duplicating the text lookup expression.






          share|improve this answer













          Form.RosterBrowser.Document returns a reference to the browser Document, so lastDoc and thisDoc are two references pointing to the same HTMLDocument object which sits somewhere on the memory heap.



          Instead you should store the value you are monitoring.

          You'd better monitor the text itself and not only its length as the text can be changed but keeping the same length.



          string lastText;

          private string GroupListText => ((HTMLDocument)Form.RosterBrowser.Document).getElementById("groupList").innerText;

          public void startTimer()
          {
          lastText = GroupListText;

          DispatcherTimer dispatcherTimer = new DispatcherTimer();
          dispatcherTimer.Tick += dispatcherTimer_Tick;
          dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
          dispatcherTimer.Start();
          }

          private void dispatcherTimer_Tick(object sender, EventArgs e)
          {
          var thisText = GroupListText;
          LogTextBlockControl.Text += "DOCUMENT THIS: " + thisText.Length.ToString();
          LogTextBlockControl.Text += "DOCUMENT LAST: " + lastText.Length.ToString();
          }


          I've used a property GroupListText to avoid duplicating the text lookup expression.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 29 '18 at 0:14









          PragmateekPragmateek

          9,36685590




          9,36685590













          • Works like a charm. I totally forgot about the stack and heap... Thankyou for the quick answer!

            – uRThow
            Nov 29 '18 at 5:54











          • I'm glad it works. :)

            – Pragmateek
            Nov 29 '18 at 10:54



















          • Works like a charm. I totally forgot about the stack and heap... Thankyou for the quick answer!

            – uRThow
            Nov 29 '18 at 5:54











          • I'm glad it works. :)

            – Pragmateek
            Nov 29 '18 at 10:54

















          Works like a charm. I totally forgot about the stack and heap... Thankyou for the quick answer!

          – uRThow
          Nov 29 '18 at 5:54





          Works like a charm. I totally forgot about the stack and heap... Thankyou for the quick answer!

          – uRThow
          Nov 29 '18 at 5:54













          I'm glad it works. :)

          – Pragmateek
          Nov 29 '18 at 10:54





          I'm glad it works. :)

          – Pragmateek
          Nov 29 '18 at 10:54




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53528840%2fwpf-c-sharp-htmldocument-variables-automatically-updates%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks