[英]Performance issue on WCF Console Application
There is a WCF service that is hosted in a .Net Console application. .Net控制台应用程序中托管有一个WCF服务。 The client creates a duplex channel to the service that has a callback. 客户端为具有回调的服务创建双工通道。 It calls the service in this way: 它以这种方式调用服务:
var task = Task<object>.Factory.FromAsync(clientRay.Proxy.BeginCalc, clientRay.Proxy.EndCalc, lst_RaySrvcDetails, state);
And here is the Main method of the service Console app: 这是服务控制台应用程序的主要方法:
static void Main(string[] args)
{
ServiceHost srvcHost = new ServiceHost(serviceInstance, uriBase);
//
//Here the service is hosted
//
while(true)
{
;
}
}
And the MyService.cs receives the call in the below method: MyService.cs通过以下方法接收呼叫:
public IAsyncResult BeginCalc(List<MBSWaldram.DataAccessLayer.Framework.ServiceDetails> input,
AsyncCallback callback, object state)
{
calcInput = input;
// Create a task to do the work
var task = Task<object>.Factory.StartNew(this.CalcTasks, state);
return task.ContinueWith(res => callback(task));
}
Now the CalcTasks method, where the actual task is run, is showing less performance compare to have it on a WCF Windows Form application. 现在,与运行WCF Windows窗体应用程序相比,运行实际任务的CalcTasks方法显示的性能更低。 One of the reason I can think of is the way I have used while(true){;} infinite loop so that the application doesn't terminates and waits for the call from the client. 我能想到的原因之一是我使用while(true){;}无限循环的方式,这样应用程序就不会终止并等待来自客户端的调用。 Not sure this the best of doing it. 不知道这是最好的做法。 For some reason I can't use Windows Form Application. 由于某些原因,我无法使用Windows窗体应用程序。
I appreciate if anyone could shed some light in why there is a performance issue here. 我很高兴有人能阐明为什么这里存在性能问题。 Thanks. 谢谢。
while (true) {;}
is really unlucky construction. while (true) {;}
确实很不幸。 In Console application take Console.ReadLine()
instead. 在控制台应用程序中,改用Console.ReadLine()
。 The application will wait until Enter press. 该应用程序将等到按下Enter键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.