How do I make this dispatch timer 1 line of code instead of this
private DispatcherTimer timer1;
public void InitTimer()
{
timer1 = new System.Windows.Threading.DispatcherTimer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = TimeSpan.FromMilliseconds(2000);
timer1.Start();
}
the x problem? it gets a null error when I uncheck it to disable it
private DispatchTimer timer1; //<- Main part of the problem?
public void InitTimer()
{
timer1 = new System.Windows.Threading.DispatcherTimer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = TimeSpan.FromMilliseconds(2000);
timer1.IsEnabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (AS.Vis.Visibility != Visibility.Visible == false)
{
AS.Vis.Visibility = Visibility.Hidden;
timer1.IsEnabled = false;
}
else
{
AS.Vis.Visibility = Visibility.Visible;
Comp();
}
}
private void AKS_Checked(object sender, RoutedEventArgs e)
{
InitTimer();
AS.Vis.Visibility = Visibility.Visible;
timer1.IsEnabled = true;// <-Also part of the problem
}
private void AKS_Unchecked(object sender, RoutedEventArgs e)
{
AS.Vis.Visibility = Visibility.Hidden;
timer1.IsEnabled = false; //<-The problem
}
I have tried some "work arounds" that I thought would end up working but they didn't so I came to the conclusion that if the dispatchtimer was one line of code it wouldn't cause a null error since private DispatchTimer timer1; bit of code wouldn't exist but I have been told that isn't really the problem?