Hi,
I am trying to make a program that is going to ping through my LAN.
I have the following code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.NetworkInformation;
namespace ScanLAN
{
public partial class frmScan : Form
{
public frmScan()
{
InitializeComponent();
}
private void frmScan_Load(object sender, EventArgs e)
{
for (int subnet = 1; subnet < 254; subnet++)
PingLAN("192.168.1." + subnet);
}
private void PingLAN(string IP)
{
try
{
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
options.DontFragment = true;
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
PingReply reply = pingSender.Send(IP, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine("Address: {0}", reply.Address.ToString());
Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
Console.WriteLine("Time to live: {0}", reply.Options.Ttl);
Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment);
Console.WriteLine("Buffer size: {0}", reply.Buffer.Length);
}
else
{
Console.WriteLine(IP + " - No Reply");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
The problem is, if I press the stop debugging button while it is running, most of the time my computer crashes to a BSOD. Does anyone know why this is happening and how I can sort it?
Loading

Suthish NairRank #92 · 22.8K reputationPosted Mar 6, 2011, 8:14 AM EST
Also, you are looping it for 254. I suggest break the loop in small units
and check how memory consumption happening.
try
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Mar 6, 2011, 7:42 AM EST
Instead of calling the PingLAN() in frmLoad Event, Place a button with name Ping and on click event of button put your PingLAN().
Just try it.
Jay Webster58 reputationPosted Mar 6, 2011, 7:56 AM EST
Thanks for your reply.
I tried what you suggested, the result was the same.
The BSOD message is PROCESS_HAS_LOCKED_PAGES and the file causing the problem is tcpip.sys
I have tried installing latest NIC drivers although it made no difference.
Jay Webster58 reputationPosted Mar 6, 2011, 8:14 AM EST
I set the timeout time to 500 and it doesnt crash :-)
Suthish NairRank #92 · 22.8K reputationPosted Mar 7, 2011, 9:37 AM EST
Jay Webster58 reputationPosted Mar 7, 2011, 1:21 PM EST