WPF C# HTMLDocument variables automatically updates
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
add a comment |
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
add a comment |
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
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
c# wpf wpf-controls mshtml
edited Nov 29 '18 at 8:22
Lennart
6,171125266
6,171125266
asked Nov 28 '18 at 22:06
uRThowuRThow
175
175
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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