需要使用队列时并且涉及多线程时使用ConcurrentQueue
这个性内比自己使用Queue并且配合lock要好很多
calcFactory = new ChannelFactory<ICalcService>(new BasicHttpBinding(BasicHttpSecurityMode.None), address); //tcp模式 calcFactory = new ChannelFactory<ICalcService>(new NetTcpBinding(SecurityMode.None), address); calcService = calcFactory.CreateChannel(); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 10; i++) { try { calcService.Add(3, 4); } catch (Exception ex) { Console.WriteLine(ex.Message); var cObj = calcService as ICommunicationObject; if (cObj.State == CommunicationState.Faulted || cObj.State == CommunicationState.Closed || cObj.State == CommunicationState.Closing ) { Console.WriteLine("status:closed,closing,faulted"); } break; } } sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds);