1

I have a C# windows service application which is interating the below code in a "foreach" loop (I got about 300 addresses to check) to determine if an IP address is reachable over the interent, unfortenutlly I get the blue screen of death, my PC crash while I debug this on Visual Studio 2019 , error code : PROCESS HAS LOCKED PAGES

public bool IsReachablePing()
        {
            try
            {
                using Ping p = new();
                PingReply reply = p.Send(IpAddress);
                if (reply.Status == IPStatus.Success) { return true; }
                return false;
            }
            catch (Exception) { return false; }
        }

How can I make this more friendly to the mechine in order to avoid a server crash in case I publish the service ? I'm afaraid to post this service on the server

  • `PROCESS HAS LOCKED PAGES` indicates a bug with a driver. That's probably a driver related to your network interface... – canton7 Aug 20 '21 at 13:55

2 Answers2

0

There's no way of fixing this through ammendments to your code, this issue is caused by sending pings during debug. You can use System.Diagnostic.Debugger.IsAttached property to determine if the debugger is attached and disable pinging. Read more here: C# program causes bluescreen?

  • Thanks for the insight but I actually was able to fix this by removing using Ping p = new(); and adding public Ping ping=new(); to the class, essentialy re-using the same instance all over again – Tom Boudniatski Aug 20 '21 at 14:12
0
using (Ping p = new Ping())
{
  // other code    
}

You used 'using' wrong. the variable p is disposed before already when you use it.

urlreader
  • 6,319
  • 7
  • 57
  • 91