태그 보관물: c#

c#

콘솔 응용 프로그램을 닫는 명령? 콘솔을 닫아야합니다. 사용 해봤는데 안되네요 close().. 어떻게 할

사용자가 메뉴 옵션을 선택할 때 콘솔을 닫아야합니다.

사용 해봤는데 안되네요 close()..

어떻게 할 수 있습니까?



답변

Environment.ExitApplication.Exit

Environment.Exit(0) 깨끗합니다.

http://geekswithblogs.net/mtreadwell/archive/2004/06/06/6123.aspx


답변

종료하면 콘솔 앱의 현재 인스턴스를 종료 하시겠습니까, 아니면 애플리케이션 프로세스를 종료 하시겠습니까? 모든 중요한 종료 코드를 놓쳤습니다.

Environment.Exit(0);

또는 양식의 현재 인스턴스를 닫으려면 :

this.Close();

유용한 링크 .


답변

당신은 이것을 시도 할 수 있습니다

Application.Exit();


답변

 //How to start another application from the current application
 Process runProg = new Process();
 runProg.StartInfo.FileName = pathToFile; //the path of the application
 runProg.StartInfo.Arguments = genArgs; //any arguments you want to pass
 runProg.StartInfo.CreateNoWindow = true;
 runProg.Start();

 //How to end the same application from the current application
 int IDstring = System.Convert.ToInt32(runProg.Id.ToString());
 Process tempProc = Process.GetProcessById(IDstring);
 tempProc.CloseMainWindow();
 tempProc.WaitForExit();


답변

return; C #에서 메서드를 종료합니다.

아래 코드 스 니펫 참조

using System;

namespace Exercise_strings
{
    class Program
    {
        static void Main(string[] args)
        {
           Console.WriteLine("Input string separated by -");

            var stringInput = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(stringInput))
            {
                Console.WriteLine("Nothing entered");
                return;
            }
}

따라서이 경우 사용자가 null 문자열이나 공백을 입력하면 return 메서드를 사용하면 Main 메서드가 우아하게 종료됩니다.


답변

따라서 응용 프로그램이 갑자기 종료되거나 종료되는 것을 원하지 않았으므로 다른 옵션으로 응답 루프가 우아하게 종료되도록 할 수 있습니다. (사용자 지침을 기다리는 while 루프가 있다고 가정합니다. 이것은 제가 오늘 작성한 프로젝트의 일부 코드입니다.

        Console.WriteLine("College File Processor");
        Console.WriteLine("*************************************");
        Console.WriteLine("(H)elp");
        Console.WriteLine("Process (W)orkouts");
        Console.WriteLine("Process (I)nterviews");
        Console.WriteLine("Process (P)ro Days");
        Console.WriteLine("(S)tart Processing");
        Console.WriteLine("E(x)it");
        Console.WriteLine("*************************************");

        string response = "";
        string videotype = "";
        bool starting = false;
        bool exiting = false;

        response = Console.ReadLine();

        while ( response != "" )
        {
            switch ( response  )
            {
                case "H":
                case "h":
                    DisplayHelp();
                    break;

                case "W":
                case "w":
                    Console.WriteLine("Video Type set to Workout");
                    videotype = "W";
                    break;

                case "I":
                case "i":
                    Console.WriteLine("Video Type set to Interview");
                    videotype = "I";
                    break;

                case "P":
                case "p":
                    Console.WriteLine("Video Type set to Pro Day");
                    videotype = "P";
                    break;

                case "S":
                case "s":
                    if ( videotype == "" )
                    {
                        Console.WriteLine("Please Select Video Type Before Starting");
                    }
                    else
                    {
                        Console.WriteLine("Starting...");
                        starting = true;
                    }
                    break;

                case "E":
                case "e":
                    Console.WriteLine("Good Bye!");
                    System.Threading.Thread.Sleep(100);
                    exiting = true;
                    break;
            }

            if ( starting || exiting)
            {
                break;
            }
            else
            {
                response = Console.ReadLine();
            }
        }

        if ( starting )
        {
            ProcessFiles();
        }


답변