Terminal.Gui: MainLoop.RunTimers() method throws System.ArgumentException after few hours.
Can someone explain me why I’m getting this error after around 8 hours of running? Terminal.Gui version 1.4
AmiAI - System.ArgumentException: An item with the same key has already been added. Key: 637865266986268040 (Parameter "key")
at System.Collections.Generic.SortedList"2.Add(TKey key, TValue value)
at Terminal.Gui.MainLoop.RunTimers()
at Terminal.Gui.MainLoop.MainIteration()
at Terminal.Gui.Application.RunLoop(RunState state, Boolean wait)
at Terminal.Gui.Application.Run(Toplevel view, Func"2 errorHandler)
at Terminal.Gui.Application.Run(Func"2 errorHandler)
at Pai.Ama.Run()
at Pai.Program.Main(String[] args)
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 23
@tznind your code modification fixed the issue on MacOS. No more problems during 23 hours.
RunTimershas an if/else statement in it. The ‘if’ condition usesAddTimerbut the ‘else’ just directly added to the dictionary. My PR adds the collision dodging to that else statement not just a new method.Old code (prior to PR)
After changing the code and starting timers via Application.Mainloop.Invoke(), the program didn’t throw any exceptions after 24 hours of running. OS: Windows, now testing MacOS.
Just done that. Now, waiting.
@BDisp checked, again same error.
No, I’m using AddTimeout function directly and call necessary actions inside bool function. I think this is why I’m getting Exception.
Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(1000), timer);