반응형
콘솔 응용 프로그램을 닫는 명령?
사용자가 메뉴 옵션을 선택할 때 콘솔을 닫아야합니다.
사용 해봤는데 안되네요 close()
..
어떻게 할 수 있습니까?
Environment.Exit
과 Application.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();
따라서 응용 프로그램이 갑자기 종료되거나 종료되는 것을 원하지 않았으므로 다른 옵션으로 응답 루프가 우아하게 종료되도록 할 수 있습니다. (사용자 지침을 기다리는 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();
}
참고URL : https://stackoverflow.com/questions/5682408/command-to-close-an-application-of-console
반응형
'IT TIP' 카테고리의 다른 글
ASP.Net MVC에서 User 개체의 UserID를 어떻게 얻습니까? (0) | 2020.10.25 |
---|---|
내 PHP 파일이 일반 텍스트로 표시되는 이유는 무엇입니까? (0) | 2020.10.25 |
Android : 어떤 상황에서 대화 상자가 나타나 onPause ()가 호출됩니까? (0) | 2020.10.25 |
파이썬에서 주어진 문자열의 가능한 모든 순열 찾기 (0) | 2020.10.25 |
독 메뉴에서 xcode 최근 프로젝트 제거 (0) | 2020.10.25 |