2015-04-21 80 views
2

無論我做什麼,我的第一個Console.Readline條目都將我從控制檯中解放出來。無論我在調試還是發佈,都會發生這種情況。ReadLine()關閉我的控制檯

我拿過去我的WriteLine

("Which Room Would you like to Trigger? \nRoom 1001 or Room 1002") 

和,只要我打的ReadLine控制檯關閉。

我仍然在學習C#,但我從來沒有遇到Python raw_input(prompt)的問題,我假設它與C#ReadLine等效。

我的代碼如下。

bool loopChk = true; 

     do 
     { 
     Console.WriteLine("Which Room Would you like to Trigger? \nRoom 1001 or Room 1002"); 
     string line = Console.ReadLine(); 
     if (line == "1001") 
     { 
      await objClient.WritePropertyAsync(fqrs[0], "Present Value", a_bOn ? "on" : "off", CancellationToken.None); 
      Console.WriteLine("You have Triggered Room 1001"); 
     } 
     else if (line == "1002") 
     { 
      await objClient.WritePropertyAsync(fqrs[1], "Present Value", a_bOn ? "on" : "off", CancellationToken.None); 
      Console.WriteLine("You have Triggered Room 1002"); 
     } 
     else if (line == "exit") 
     { 
      break; 
     } 
     } while (loopChk); 
+0

把一個'到Console.ReadLine()''該做,while'循環之後。 –

+0

@jsve只要我輸入一個值並按下輸入關閉,就不會執行任何操作。 – Phi

+0

這就是它應該做的。這不是你想要的嗎?等到用戶在退出程序之前按下Enter鍵?我想我不太理解你的問題。 –

回答

0

試試這個:

string line = null; 

do { 
    Console.WriteLine("Which Room Would you like to Trigger? \nRoom 1001 or Room 1002"); 
    line = Console.ReadLine(); 

    if (line == "1001") 
    { 
     await objClient.WritePropertyAsync(fqrs[0], "Present Value", a_bOn ? "on" : "off", CancellationToken.None); 
     Console.WriteLine("You have Triggered Room 1001"); 
    } 
    else if (line == "1002") 
    { 
     await objClient.WritePropertyAsync(fqrs[1], "Present Value", a_bOn ? "on" : "off", CancellationToken.None); 
     Console.WriteLine("You have Triggered Room 1002"); 
    } 
} while (line != "exit") 
+0

仍然不起作用。 – Phi

+0

當你一行一行地完成代碼時會發生什麼? –

+0

你也可以嘗試註釋掉'await'這兩行,看看是否有所作爲。 –