public void OnDeserialization(object sender) { ItemType[] serializedItems; lock (this) { serializedItems = _items.ToArray(); _items.Clear(); } foreach (ItemType item in serializedItems) {// Resubscribe for events etc. Add(item); } }
/// <summary> /// Will clear class filters and sinks (or optionaly also remove them). /// </summary> /// <param name="completeClear">Will also remove the sinks and filters. Pass false to only clear them.</param> public void Clear(bool completeClear) { ITracerItemSink[] sinks; lock (this) { sinks = _itemSinks.ToArray(); } foreach (ITracerItemSink sink in sinks) { sink.Clear(); if (completeClear) { sink.Dispose(); } } if (completeClear) { lock (this) { _itemSinks.Clear(); _filters.Clear(); } } if (TracerClearedEvent != null) { TracerClearedEvent(this, completeClear); } }