Necesito cerrar la consola cuando el usuario selecciona una opción de menú.¿Comando para cerrar una aplicación de la consola?
He intentado utilizar close()
pero no funcionó ..
cómo puedo hacer esto?
Necesito cerrar la consola cuando el usuario selecciona una opción de menú.¿Comando para cerrar una aplicación de la consola?
He intentado utilizar close()
pero no funcionó ..
cómo puedo hacer esto?
Environment.Exit
y Application.Exit
Environment.Exit(0)
es más limpio.
http://geekswithblogs.net/mtreadwell/archive/2004/06/06/6123.aspx
Por fin, ¿quiere decir que desea que la instancia actual de la aplicación de consola para cerrar, o no desea que el proceso de solicitud, a finalizar? Missed que todo el código de salida importante:
Environment.Exit(0);
O para cerrar la instancia actual de la forma:
this.Close();
Útil link.
puede probar esta
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();
Así que no dijo que quería la salida de una aplicación o la salida abrupta, así como otra opción, tal vez sólo tiene el bucle termina respuesta a cabo con elegancia. (Supongo que tiene un bucle while esperando instrucciones de usuario. Este es un código de un proyecto que acabo de escribir hoy.
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();
}
Sólo curiosidad: ¿Qué objeto intentó llamar. Cerrar()? –