I'm trying to manage asynchronous method calls with a
System.Threadin g.Timer object and need help determining
the best way to do so.
Currently, I have a private Timer variable in Class1
called refreshTimer. Inside the default Class1
constructor, refreshTimer is initialized with a
TimerCallback ("Refresh"), a null object, 0 dueTime & a
period taken from an XML file. The following code
demonstrates:
public class Class1 {
private refreshTimer;
...
public Class1(){
...
refreshTimer = new Timer(new TimerCallback
(Refresh), null, 0, someXmlValue);
...
}
...
private void Refresh(object sender){
...
}
}
That works well & good, but I'm unclear as to the best
way to manage the Period value if the XML file changes.
I've considered the following two approaches and have the
feeling that a better way is out there:
1. Add a second Timer that queries the XML value every
so often and re-initializes the RefreshTimer if it has
changed. This seems overly complex.
2. Add code to the Refresh method that checks the XML
value and calls "refreshTimer.C hange()" with the
appropriate new values. This seems messy, since it was
refreshTimer that triggered this method in the first
place.
Thoughts?
Bill
System.Threadin g.Timer object and need help determining
the best way to do so.
Currently, I have a private Timer variable in Class1
called refreshTimer. Inside the default Class1
constructor, refreshTimer is initialized with a
TimerCallback ("Refresh"), a null object, 0 dueTime & a
period taken from an XML file. The following code
demonstrates:
public class Class1 {
private refreshTimer;
...
public Class1(){
...
refreshTimer = new Timer(new TimerCallback
(Refresh), null, 0, someXmlValue);
...
}
...
private void Refresh(object sender){
...
}
}
That works well & good, but I'm unclear as to the best
way to manage the Period value if the XML file changes.
I've considered the following two approaches and have the
feeling that a better way is out there:
1. Add a second Timer that queries the XML value every
so often and re-initializes the RefreshTimer if it has
changed. This seems overly complex.
2. Add code to the Refresh method that checks the XML
value and calls "refreshTimer.C hange()" with the
appropriate new values. This seems messy, since it was
refreshTimer that triggered this method in the first
place.
Thoughts?
Bill