From 080f1697e97e13461ec6df4d31c8924d01257a1b Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 9 Apr 2019 01:47:48 +0300 Subject: MERGE --- .../Tango.Scripting.Editors/Utils/DelayedEvents.cs | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Utils/DelayedEvents.cs (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Utils/DelayedEvents.cs') diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Utils/DelayedEvents.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Utils/DelayedEvents.cs new file mode 100644 index 000000000..8afc9f2ee --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Utils/DelayedEvents.cs @@ -0,0 +1,48 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; + +namespace Tango.Scripting.Editors.Utils +{ + /// + /// Maintains a list of delayed events to raise. + /// + sealed class DelayedEvents + { + struct EventCall + { + EventHandler handler; + object sender; + EventArgs e; + + public EventCall(EventHandler handler, object sender, EventArgs e) + { + this.handler = handler; + this.sender = sender; + this.e = e; + } + + public void Call() + { + handler(sender, e); + } + } + + Queue eventCalls = new Queue(); + + public void DelayedRaise(EventHandler handler, object sender, EventArgs e) + { + if (handler != null) { + eventCalls.Enqueue(new EventCall(handler, sender, e)); + } + } + + public void RaiseEvents() + { + while (eventCalls.Count > 0) + eventCalls.Dequeue().Call(); + } + } +} -- cgit v1.3.1