Hello community,

I am pretty new to c# and i have decided to use COSMOS to build a basic operating system,
However, all my code compiles correctly but there is one problem, when i type shutdown, the system hangs, it does not shutdown and the white cursor continues flashing but i cannot type anything. ideally i would like it so that the system automatically powers down after the shutdown command is issued. My code so far:

using System;
using Cosmos.Compiler.Builder;

namespace CosmosBoot1
{
    class Program
    {
        #region Cosmos Builder logic
        // Most users wont touch this. This will call the Cosmos Build tool
        [STAThread]
        static void Main(string[] args)
        {
            BuildUI.Run();
        }
        #endregion

        // Main entry point of the kernel
        public static void Init()
        {
            var xBoot = new Cosmos.Sys.Boot();
            xBoot.Execute();
            Console.WriteLine("BAILEYTEK OS 2012 BETA");
            Console.Beep(1000, 1000);
            // Start of session
            Console.WriteLine("SESSION START");
        // read command
        command:
            Console.Write("-->");
            while (true)
            {
                string command = Console.ReadLine();
                switch (command)
                // Base commands 
                {
                    case "about":
                        {
                            Console.WriteLine("BAILEYTEK operating system 2012 beta developed by cyberdan123");
                            Console.WriteLine("Support email: cyberdan1234@live.co.uk");
                            goto command;
                        }
                    case "clear":
                        {
                            Console.Clear();
                            Console.WriteLine("BAILEYTEK OS 2012 BETA");
                            goto command;
                        }

                    case "shutdown":
                        {

                            Cosmos.Sys.Deboot.ShutDown();
                            break;
                        }
                    // help

                    case "help":
                        {
                            Console.Clear();
                            Console.WriteLine("BAILEYTEK OS 2012 BETA");
                            Console.WriteLine("User Guide");
                            Console.WriteLine("================================================================================");
                            Console.WriteLine("ABOUT    : Display information about system.");
                            Console.WriteLine("CLEAR    : Clear user interface.");
                            Console.WriteLine("HELP     : Display list of commands.");
                            Console.WriteLine("START    : Load main program");
                            Console.WriteLine("SHUTDOWN : End current session and power off machine");
                            Console.WriteLine("");
                            Console.WriteLine("================================================================================");
                            goto command;

                        }


                    //main program

                    case "start":
                        {
                            Console.WriteLine("Main program will exist here but i haven't planned it yet.");
                            goto command;
                        }



                    //if command is incorrect
                    default:
                        {
                            Console.WriteLine("Command Invalid");
                            goto command;
                        }

                        ;
                }
            }
        }
    }
}

Could anyone please suggest a way to fix this error,
Thanks in advance
Cyberdan :)

At line 52 you are breaking out of the switch case clause.
This does not break your while loop.

Try restructuring your code as follows:

First get rid of all those goto command statements and let the while loop to do its job.
Use a break at the end of each of the case statements instead.
Move line 28 inside the while loop and get rid of the command: label.

To manage the shutdown use a boolean in the while statement e.g.

bool shutdown = false;
while (!shutdown)
{...}

Now set the boolean to true in the shutdown case.

ok i will try that thanks for your help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.