-1

I am checking internet connection in my C# code using this code..

WebClient workstation = new WebClient();

byte[] data = workstation.DownloadData("http://www.google.com");

It is working fine on another pc (returning result everytime), but on my pc (windows 7, 64 bit) sometimes it is showing "operation time out error"(System.Net.WebException). Is this pc specific issue, tried in different environment but not getting any clue..

Lennart
  • 9,657
  • 16
  • 68
  • 84
Deepak gupta
  • 1,938
  • 11
  • 11
  • So your checking your internet connection, and wondering why its timing out when it has problems downloading from the internet? This is all self explanatory really. I mean, for what ever reason `DownloadData` is timing out, meaning you have a problem with accessing that url, whether its a router issue, whether its blocked at the firewall or many other reasons. its just timing out. it has nothing to do with windows 7. The point of all this is, something is wrong, and there is really no way we can know what it is – TheGeneral Jul 28 '18 at 06:54
  • Url is accessible in browser. – Deepak gupta Jul 28 '18 at 06:56
  • It could be packet collision with improperly configured network and many other network problems. I very much doubt this is anything to do with WebClient, windows 7 or C# or visual studio, especially because this is intermittent, it might even be your virus scanner – TheGeneral Jul 28 '18 at 07:00
  • 1
    What version of the .Net framework are you using on the Win 7 PC? If it is less than 4.5 you might have to [explicitly set the TLS version](https://stackoverflow.com/questions/37869135/is-that-possible-to-send-httpwebrequest-using-tls1-2-on-net-4-0-framework/37869237#37869237) – Crowcoder Jul 28 '18 at 10:05
  • Just because you can retrieve a webpage from google, that doesn't guarantee that any future activity (nanoseconds in the future or longer) will be able to complete if those activities rely on network communications, including internet access. That's why this sort of check is almost always *pointess*. You have to write the actual code to deal with actual failures which can occur at *any* time. – Damien_The_Unbeliever Jul 30 '18 at 08:26

1 Answers1

0

Finally got a solution..

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.DefaultConnectionLimit = 9999;
valentasm
  • 2,137
  • 23
  • 24
Deepak gupta
  • 1,938
  • 11
  • 11