1

So after 36 hours of research and checking, I got it.

VS2012 Is the cause after the 'process has locked pages' BSOD.

I tried to open a thread to get the active IPs on my network (using C#). Apparently, When you press the 'Stop' Button when the thread is active, windows is crushing.

This is the thread code:

    private void Button_Click_2(object sender, RoutedEventArgs e)
    {

        var thread = new Thread(() => TryToConnect(targetsList));

        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();
        thread.Join();

    }

    private static void TryToConnect(ListBox targetsList)
    {
        for (int i = 1; i < 3; i++)
        {
            Uri url = new Uri("http://192.168.1." + i.ToString());
            string pingurl = string.Format("{0}", url.Host);
            string host = pingurl;
            Ping p = new Ping();
            try
            {
                PingReply reply = p.Send(host, 3000);
                if (reply.Status == IPStatus.Success)
                {
                    ListBoxItem item = new ListBoxItem();
                    item.Content = "192.168.1." + i.ToString();
                    targetsList.Items.Add(item);
                    targetsList.Items.Refresh();
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //   Thread.Sleep(10);
        }
    }

As you can see the thread is using Ping 255 times, so it takes time to be finished. When I press the Stop button apparently the VS2012 Debug Process makes Windows to crush. Every time that I tried it, Windows crashed. (My OS: Win7 64Bit) Am I right with this? And if not, is it fixable?

albeck
  • 510
  • 1
  • 7
  • 16
  • 3
    VS2012? or your code? hmmm.... – Mitch Wheat Jul 09 '13 at 00:18
  • @MitchWheat his code. – evanmcdonnal Jul 09 '13 at 00:19
  • @MitchWheat Are you sure about that? why is my code makes Windows to crash? – albeck Jul 09 '13 at 00:24
  • 1
    It's probably neither your code nor VS2012, but rather a faulty driver (possibly network-related.) It's *very* hard for user-mode programs to BSOD your computer (and when you do so, it's by interacting with a kernel-mode component in a particular way.) – dlev Jul 09 '13 at 00:31
  • Your thread code is directly accessing UI elements that were created on the UI thread.. which is not a good idea. I wouldn't expect a BSOD, though. You haven't shown us the stop button code? – Blorgbeard Jul 09 '13 at 00:32
  • 1
    Looks like it's a known issue: http://connect.microsoft.com/VisualStudio/feedback/details/721557/bluescreen-process-has-locked-pages-netframework-ping-send – Blorgbeard Jul 09 '13 at 00:33
  • @dlev Its occur only when I hit the Stop button of VS2012 (@Blogbeard the stop button is VS's one) – albeck Jul 09 '13 at 00:34
  • There is a work-around to this [here](https://stackoverflow.com/questions/17756824/blue-screen-when-using-ping/45409827#45409827) I had the same problem – Brain Bytes Jul 31 '17 at 08:39

2 Answers2

4

It's a known issue with Visual Studio (since VS2010, apparently) and the Ping class.

Posted by Microsoft on 06/02/2012 at 09:11
Thank you for your feedback. This is a known issue with the underlying Windows APIs used by the Ping class. The Windows team is will determine how to best handle the issue.

Freggar
  • 1,049
  • 1
  • 11
  • 24
Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
  • I haven't find that when I looked for that. I tried re installing VS, and I installed Update 3. I replaced my remote mouse & keyboard, my VGA and DVI drivers.. Thank you! – albeck Jul 09 '13 at 00:41
  • 2017 and apparently still not fixed. – CoderBrien Feb 24 '17 at 18:23
0

Directly operate UI in the thread will crash.You should use Invoke or BeginInvoke.Invoke is synchronization.BeginInvoke is asynchronization.

 this.Invoke(new EventHandler(delegate
        {
            ListBoxItem item = new ListBoxItem();
            item.Content = "192.168.1." + i.ToString();
            targetsList.Items.Add(item);
            targetsList.Items.Refresh();
        }));
user2492798
  • 589
  • 1
  • 4
  • 8