/// <summary> /// 释放资源 /// </summary> public void Dispose() { isDisposed = 1; Monitor.Enter(serverLock); pub.Dispose(ref server); Monitor.Exit(serverLock); int count = 0; clientType[] clients; do { clients = new clientType[this.clients.Length]; Monitor.Enter(clientLock); currentIndex = callCount = 0; if (currentCount <= clients.Length) { while (count != currentCount) { clients[count++] = this.clients[count++].Client.GetRemove(); } freeIndexs.Clear(); currentCount = 0; Monitor.Exit(clientLock); break; } else { Monitor.Exit(clientLock); } }while (true); while (count != 0) { pub.Dispose(ref clients[--count]); } }
/// <summary> /// 数据文本分词 /// </summary> /// <param name="text">文本</param> /// <returns>分词结果</returns> protected unsafe Dictionary <hashString, list <int> > getAllWords(string text) { if (text != null) { int length = text.Length; if (length != 0) { list <subString> words = getWords(text + " ", length); if (words != null) { Dictionary <hashString, list <int> > dictionary = typePool <Dictionary <hashString, list <int> > > .Pop(); if (dictionary == null) { dictionary = fastCSharp.dictionary.CreateHashString <list <int> >(); } else if (dictionary.Count != 0) { dictionary.Clear(); } list <int> indexs; int count = words.Count; foreach (subString word in words.UnsafeArray) { hashString wordKey = word; if (!dictionary.TryGetValue(wordKey, out indexs)) { indexs = typePool <list <int> > .Pop(); if (indexs == null) { indexs = new list <int>(); } else { indexs.Empty(); } dictionary.Add(wordKey, indexs); } indexs.Add(word.StartIndex); if (--count == 0) { break; } } words.Clear(); typePool <list <subString> > .PushNotNull(words); return(dictionary); } } } return(null); }
/// <summary> /// 释放资源 /// </summary> private void dispose() { while (Interlocked.CompareExchange(ref threadLock, 1, 0) != 0) { Thread.Sleep(1); } try { if (!isDisposed) { isDisposed = true; foreach (thread thread in threads) { thread.Stop(); } threads.Clear(); } } finally { threadLock = 0; } }
/// <summary> /// 释放资源 /// </summary> public void Dispose() { Monitor.Enter(clientLock); isStop = true; Monitor.Exit(clientLock); Monitor.Enter(waitLock); try { Monitor.PulseAll(waitLock); } finally { Monitor.Exit(waitLock); } foreach (fastCSharp.net.tcpClient value in clients) { try { value.Dispose(); } catch { } } clients.Clear(); }