void SyncWorker(ChatModel chatModel) { try { var chatKey = GetChatKey(chatModel); AutoResetEvent syncWait = null; lock (SyncWaitQueue) { SyncWaitQueue.TryGetValue(chatKey, out syncWait); } if (syncWait != null) { #if LOG4NET Logger.Debug("SyncWorker() <" + chatKey + "> waiting for " + "sync lock release..."); #endif // This chat was queued by QueueAdd() thus we need to wait // till the ChatView is created and ready to be synced syncWait.WaitOne(); #if LOG4NET Logger.Debug("SyncWorker() <" + chatKey + "> " + "sync lock released"); #endif // no longer need the sync lock lock (SyncWaitQueue) { SyncWaitQueue.Remove(chatKey); } } IChatView chatView = null; lock (SyncReleaseQueue) { if (!SyncReleaseQueue.TryGetValue(chatKey, out chatView)) { #if LOG4NET Logger.Warn("SyncWorker(): chatView is null! " + "probably a reconnect, bailing out..."); #endif return; } // no longer need the release slot // BUG: this breaks re-syncing an existing chat! For that // reason the frontend _must_ notify us via Remove() if the // chat sync state is no longer needed //SyncReleaseQueue.Remove(chatKey); } Sync(chatView); } catch (Exception ex) { #if LOG4NET Logger.Error("SyncWorker(): Exception!", ex); #endif OnWorkerException(chatModel, ex); } }
void SyncWorker(ChatModel chatModel) { try { var chatKey = GetChatKey(chatModel); AutoResetEvent syncWait = null; lock (SyncWaitQueue) { SyncWaitQueue.TryGetValue(chatKey, out syncWait); } if (syncWait != null) { #if LOG4NET Logger.Debug("SyncWorker() <" + chatKey + "> waiting for " + "sync lock release..."); #endif // This chat was queued by QueueAdd() thus we need to wait // till the ChatView is created and ready to be synced syncWait.WaitOne(); #if LOG4NET Logger.Debug("SyncWorker() <" + chatKey + "> " + "sync lock released"); #endif // no longer need the sync lock lock (SyncWaitQueue) { SyncWaitQueue.Remove(chatKey); } } IChatView chatView = null; lock (SyncReleaseQueue) { SyncReleaseQueue.TryGetValue(chatKey, out chatView); } Sync(chatView); } catch (Exception ex) { #if LOG4NET Logger.Error("SyncWorker(): Exception!", ex); #endif } }