I am trying to set up a timer and for some reason I keep getting errors when I try to recursively call ProcessStateChangedQueue()
. I originally tried using Timer
instead of DispacherTimer
, but this is a WPF application. I could have done timer.elapsed if I used timer, but can't in this case. Seems as though I have to use timer.tick. I have never used this before. You can see where timer.elapsed is commented out, I just need to fix this to where I can recursively call ProcessStateChangedQueue()
as coded below. The only error is No overload for "ProcessStateChangedQueue" matches delegate "System.EventHandler"
Maybe I should not use EventHandler
. I am just not sure... any ideas?
#region ********** STATE **********
public delegate void MapStateChangedHandler(object sender, MapStateEventArgs e);
public event MapStateChangedHandler MapStateChanged;
private Queue<String> stateChangedQueue = new Queue<String>();
private bool processingStateChanged = false;
private void RaiseMapStateChanged(string property)
{
if (!CanSaveState) return;
RebuildState();
if (MapStateChanged != null)
{
//MapStateChanged(this, new MapStateEventArgs(property, State));
stateChangedQueue.Enqueue(property);
if (!processingStateChanged)
{
ProcessStateChangedQueue();
}
}
}
private void ProcessStateChangedQueue()
{
if (stateChangedQueue.Count != 0)
{
processingStateChanged = true;
MapStateChanged(this, new MapStateEventArgs(stateChangedQueue.Dequeue(), State));
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(500);
//timer.Elapsed = timer.Elapsed + new ElapsedEventHandler(ProcessStateChangedQueue);
timer.Tick += new EventHandler(ProcessStateChangedQueue);
timer.Start();
}
else
{
processingStateChanged = false;
}
}
private void RebuildState()
{
State.IsMonochrome = Monochrome;
State.SelectedMapIndex = MapTileLayers.IndexOf(SelectedBaseMap);
Dictionary<int, double> overlays = new Dictionary<int, double>();
foreach (MapOverlay overlay in MapOverlays)
{
if (overlay.IsVisible)
overlays.Add(MapOverlays.IndexOf(overlay), overlay.Opacity);
}
State.MapOverlays = overlays;
State.ContrastValue = Contrast;
}