Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# program causes bluescreen?

This is only the important stuff that the bluescreen shows. I'm on Windows 7 x64.

"A problem has been detected and Windows has been shut down to prevent damage to your computer.

PROCESS_HAS_LOCKED_PAGES

* STOP: 0x00000076 (0x0000000000000000, 0xfffffa8009dcd060, 0x0000000000000011, 0x0000000000000000)"

I can't work on it now because every time I close it I get a bluescreen! The program doesn't do anything yet except run the background worker below. It pings all addresses that could be part of the user's home network and attempts to connect to a certain port that another program will be listening on.

private void NetworkScanner_DoWork(object sender, DoWorkEventArgs e)
    {
        bool ExceptionEncountered = false;
        int IPsProcessed = 0;

        NetworkSearcherOutput = "Starting network scanner...";
        NetworkSearcher.ReportProgress(0);
        Thread.Sleep(1000);

        foreach (IPAddress IP in Dns.GetHostAddresses(Dns.GetHostName()))
        {
            if (IP.AddressFamily == AddressFamily.InterNetwork)
            {
                string[] Octets = IP.ToString().Split('.');
                Octets[3] = "0";

                IPAddress CurrentAddressIteration = StringArrayToIP(Octets);
                while (GetLastOctet(CurrentAddressIteration) != 255)
                {
                    PingReply Reply = new Ping().Send(CurrentAddressIteration, 5);

                    if (Reply.Status == IPStatus.Success)
                    {
                        NetworkSearcherOutput = CurrentAddressIteration.ToString() + " sent response.";
                        NetworkSearcher.ReportProgress(0);
                        Thread.Sleep(500);

                        InClient Client = new InClient(CurrentAddressIteration);

                        try
                        {
                            Client.Connect();

                            SnapshotBox.Image = Client.Receive(typeof(Image));

                            NetworkSearcherOutput = CurrentAddressIteration.ToString() + " is running program.";
                            NetworkSearcher.ReportProgress(0);
                            Thread.Sleep(1000);
                        }

                        catch (Exception E)
                        {
                            // A socket exception is expected when the client is not running the program.
                            if (E is SocketException)
                            {
                                Client.Close();

                                NetworkSearcherOutput = CurrentAddressIteration.ToString() + " is not running program.";
                                NetworkSearcher.ReportProgress(0);
                                Thread.Sleep(1000);
                            }

                            //Unhandled exception. Show messagebox and close.
                            else
                            {
                                MessageBox.Show("Network scanner encountered an unhandled exception.\n\n" + E.GetType().ToString() + ": " + E.Message, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                ExceptionEncountered = true;
                                break;
                            }
                        }
                    }

                    else
                    {
                        NetworkSearcherOutput = CurrentAddressIteration.ToString() + " did not respond.";
                        NetworkSearcher.ReportProgress(0);
                    }

                    IPsProcessed++;

                    if (IPsProcessed == 5)
                    {
                        NetworkSearcher.ReportProgress(2);
                        IPsProcessed = 0;
                    }

                    Octets = CurrentAddressIteration.ToString().Split('.');
                    Octets[3] = (Int32.Parse(Octets[3]) + 1).ToString();
                    CurrentAddressIteration = StringArrayToIP(Octets);
                }
            }
        }

        if (!ExceptionEncountered)
        {
            NetworkSearcherOutput = "Network scanning complete.";
            NetworkSearcher.ReportProgress(0);
            NetworkSearcher.ReportProgress(100);
        }

        else
        {
            NetworkSearcherOutput = "Network scanning encountered an error.";
            NetworkSearcher.ReportProgress(-1);
        }

I thought C# programs were supposed to never cause bluescreens?

like image 226
WildBamaBoy Avatar asked Nov 02 '11 04:11

WildBamaBoy


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.


2 Answers

I discovered this issue a few weeks back. It only happens when using .NET 4.

Reported at MS Connect.

Edit:

(Will*) Add this link to MS Connect bug report.

*login.live.com is going into an infinite loop again...

like image 60
leppie Avatar answered Sep 19 '22 03:09

leppie


Just to be clear, there is no way for "user" mode code to forcibly create a blue screen in windows, unless it uses undocumented APIs and or forces bad data into a driver. Your C# code is likely not be at fault here, as if you use the user mode classes (Socket) then the socket is responsible for not crashing your computer.

As @Joe has commented Microsoft Support KB Article 256010 clearly describes this stop message, but better yet has clear instructions on capturing the driver name responsible for this error.

Note that any software firewall that you have installed also is involved at kernel mode level so could also be responsible for this error. I recommend you follow the KB articles advice and try to find out what is at fault. But you could also ensure that you have updated your network drivers and firewall/VPN software to the latest stable versions.

like image 41
Spence Avatar answered Sep 21 '22 03:09

Spence