How do I check an instance variable from a MVVM DispatchTimer class?

  • Thread starter Thread starter dydx123
  • Start date Start date
D

dydx123

Guest
So, I have this class for dealing with timers in MVVM:



class RecognitionProcessTimer
{
DispatcherTimer analysisProcessTimer;
public int Duration { get; set; }
public RecognitionProcessTimer()
{
this.Duration = 500;
}

public void StartTimer()
{
analysisProcessTimer = new DispatcherTimer();
analysisProcessTimer.Interval = TimeSpan.FromMilliseconds(this.Duration);
analysisProcessTimer.Tick += AnalysisProcessTimer_Tick;
analysisProcessTimer.Start();
}

public void StopTimer()
{
if (analysisProcessTimer != null)
{
analysisProcessTimer.Stop();
analysisProcessTimer = null;
}
}

private void AnalysisProcessTimer_Tick(object sender, object e)
{
analysisProcessTimer.Stop();
// C# code current object variables from the other class
}
}


So, I have an analysis class that will do analysis on every tick of the timer. The RecognitionProcessTimer will be initialized and Start() on this analysis class's code but the timer's AnalysisProcessTimer_Tick event needs to check and call some current analysis class object variables. How do I go on achieving this?

I've tried to initialize the analysis class on tick method but then I lose all the data on there as a new object is used instead of the using the object that initialize the RecognitionProcessTimer class.

TLDR: I'm trying to use the variables from the class that initialized RecognitionProcessTimer from RecognitionProcessTimer's tick method.

If the question seems unclear, then please let me know and I'll clarify further. P.S: Can't use static variables.

Continue reading...
 
Back
Top