需要使用队列时并且涉及多线程时使用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);
View Code

相关文章:

  • 2021-08-07
  • 2021-12-18
  • 2021-12-22
  • 2021-09-08
  • 2021-11-08
猜你喜欢
  • 2021-06-12
  • 2021-08-12
  • 2022-12-23
  • 2021-12-18
  • 2021-04-22
  • 2022-02-04
相关资源
相似解决方案