简体   繁体   English

C#Hammock库RestClient.BeginRequest阻止当前线程

[英]C# Hammock library RestClient.BeginRequest blocks current thread

I'm using the awesome Hammock REST library (https://github.com/danielcrenna/hammock) for .NET C#, and I've encountered a problem with RestClient.BeginRequest. 我正在使用适用于.NET C#的很棒的Hammock REST库(https://github.com/danielcrenna/hammock),而RestClient.BeginRequest遇到了问题。 The first time this method gets called in my code, it blocks the current thread for a good 15 seconds. 第一次在我的代码中调用此方法时,它将阻塞当前线程15秒钟。 I was under the impression this method is an asynchronous operation because it returns an IAsyncResult and accepts a callback - it should return immediately, right? 我印象中,此方法是异步操作,因为它返回IAsyncResult并接受回调-它应立即返回,对吗?

I know the problem is with BeginRequest because a debugging session will show it hanging on that specific line of code - in other words, the problem isn't related to internet connectivity problems or latency between the REST resource and my local machine. 我知道问题出在BeginRequest上,因为调试会话将显示它挂在特定的代码行上-换句话说,问题与Internet连接问题或REST资源与本地计算机之间的延迟无关。

I could dive into the source code for Hammock, but it's pretty confusing in there - has anyone encountered this problem before? 我可以深入研究Hammock的源代码,但是在那儿却很令人困惑-以前有人遇到过这个问题吗? Is this just a bug in Hammock or is it expected behavior? 这仅仅是Hammock中的错误,还是预期的行为? I'm having a tough time finding much documentation. 我很难找到很多文档。 Thanks in advance for your help! 在此先感谢您的帮助!

Is your end point you are connecting to using SSL/TLS? 您是使用SSL / TLS连接的端点吗? If so, sometimes these delays can be caused by the client attempting to check the revocation list of the SSL certificate. 如果是这样,有时这些延迟可能是由客户端尝试检查SSL证书的吊销列表引起的。 In .NET you can change the revocation mode using the following code. 在.NET中,您可以使用以下代码更改吊销模式。

client.ClientCredentials.ServiceCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck;

I am not sure how you could do this in Hammock. 我不确定您如何在Hammock中做到这一点。

I think this is a property of Dotnet webclient/httprequest, specifically, it seems to do a check for the proxy settings of the machine on the first request. 我认为这是Dotnet webclient / httprequest的属性,具体地说,它似乎在第一个请求时检查了计算机的代理设置。

I've found you can get a big speed up by explicitly setting the proxy in the app.config. 我发现通过在app.config中显式设置代理可以大大提高速度。 Alternatively you could make your first request on a different thread manually I think. 另外,我认为您可以在其他线程上手动发出第一个请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM