2011-04-15 12 views
52

जब उपयोगकर्ता मेनू विकल्प का चयन करता है तो मुझे कंसोल बंद करने की आवश्यकता होती है।कंसोल के आवेदन को बंद करने के लिए कमांड?

मैं close() उपयोग करने की कोशिश, लेकिन यह काम नहीं किया ..

मैं यह कैसे कर सकते हैं?

+1

बस उत्सुक: आपने किस ऑब्जेक्ट को कॉल करने का प्रयास किया था। –

उत्तर

21

पास रखकर आप मतलब आप कंसोल ऐप्स को बंद करने की वर्तमान उदाहरण चाहते हैं, या आप आवेदन प्रक्रिया चाहते हैं, समाप्त करने के लिए? मिस्ड कि सभी महत्वपूर्ण बाहर निकलें कोड:

Environment.Exit(0); 

या प्रपत्र की वर्तमान उदाहरण बंद करने के लिए:

this.Close(); 

उपयोगी link

6

आप प्रयास करें यह

Application.Exit(); 
1
//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(); 
0

तो तुम यह नहीं कहा कि आप आवेदन छोड़ने की या बाहर निकलने के अचानक है, तो एक और विकल्प के रूप में, शायद सिर्फ प्रतिक्रिया पाश सुंदर ढंग से बाहर अंत है चाहता था कर सकते हैं। (मुझे लगता है कि आपके पास उपयोगकर्ता निर्देशों के लिए थोड़ी देर की प्रतीक्षा है। यह एक परियोजना से कुछ कोड है जिसे मैंने अभी लिखा है।

 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(); 
     } 
संबंधित मुद्दे