It seems like an error when the recording timeout specified in the Stream instance returned to you by BeginGetRequestStream () does not extend to the native socket. I will log an error to make sure that this problem is fixed for a future version of the .NET Framework.
Here is a workaround.
private static void SetRequestStreamWriteTimeout(Stream requestStream, int timeout)
{
if (!s_requestStreamWriteTimeoutWorkaroundFailed)
{
try
{
Type connectStreamType = requestStream.GetType();
FieldInfo fieldInfo = connectStreamType.GetField("m_Chunked", BindingFlags.NonPublic | BindingFlags.Instance);
fieldInfo.SetValue(requestStream, true);
}
catch (Exception)
{
s_requestStreamWriteTimeoutWorkaroundFailed = true;
}
}
requestStream.WriteTimeout = timeout;
}
private static bool s_requestStreamWriteTimeoutWorkaroundFailed;
source
share