集合已被修改;枚举操作可能不会执行。
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]public class SubscriptionServer : ISubscriptionServer{ private static IDictionary<Guid, Subscriber> subscribers; public SubscriptionServer() { subscribers = new Dictionary<Guid, Subscriber>(); } public void NotifySubscribers(DataRecord sr) { foreach(Subscriber s in subscribers.Values) { try { s.Callback.SignalData(sr); } catch (Exception e) { DCS.WriteToApplicationLog(e.Message, System.Diagnostics.EventLogEntryType.Error); UnsubscribeEvent(s.ClientId); } } } public Guid SubscribeEvent(string clientDescription) { Subscriber subscriber = new Subscriber(); subscriber.Callback = OperationContext.Current. GetCallbackChannel<IDCSCallback>(); subscribers.Add(subscriber.ClientId, subscriber); return subscriber.ClientId; } public void UnsubscribeEvent(Guid clientId) { try { subscribers.Remove(clientId); } catch(Exception e) { System.Diagnostics.Debug.WriteLine("Unsubscribe Error " + e.Message); } }}
神不在的星期二
元芳怎么了
月关宝盒