diff --git a/src/TextMateSharp/Model/TMModel.cs b/src/TextMateSharp/Model/TMModel.cs index 896c8fb..fc14ced 100644 --- a/src/TextMateSharp/Model/TMModel.cs +++ b/src/TextMateSharp/Model/TMModel.cs @@ -327,7 +327,11 @@ public void RemoveModelTokensChangedListener(IModelTokensChangedListener listene public void Dispose() { - listeners.Clear(); + lock (listeners) + { + listeners.Clear(); + } + Stop(); GetLines().Dispose(); } @@ -375,15 +379,18 @@ private void BuildEventWithCallback(Action callb private void Emit(ModelTokensChangedEvent e) { - foreach (IModelTokensChangedListener listener in listeners) + lock (listeners) { - try - { - listener.ModelTokensChanged(e); - } - catch (Exception ex) + foreach (IModelTokensChangedListener listener in listeners) { - System.Diagnostics.Debug.WriteLine(ex.Message); + try + { + listener.ModelTokensChanged(e); + } + catch (Exception ex) + { + System.Diagnostics.Debug.WriteLine(ex.Message); + } } } }