我想知道你是否可以通過讓用戶輸入一個字符串(最低,BelowNormal等)來改變線程的優先級?據我所知,「ThreadPriority」是一個枚舉,但我不知道該怎麼做。用console.readline設置線程優先級? c#
thread.Priority = ThreadPriority.BelowNormal
如何將BelowNormal更改爲用戶輸入的內容(ReadLine)?
謝謝!
我想知道你是否可以通過讓用戶輸入一個字符串(最低,BelowNormal等)來改變線程的優先級?據我所知,「ThreadPriority」是一個枚舉,但我不知道該怎麼做。用console.readline設置線程優先級? c#
thread.Priority = ThreadPriority.BelowNormal
如何將BelowNormal更改爲用戶輸入的內容(ReadLine)?
謝謝!
thread.Priority = (ThreadPriority)Enum.Parse(typeof(ThreadPriority), Console.ReadLine());
謝謝!我真的很感激快速回復! –
你可以解析字符串,做一個條件
string userinput = Console.ReadLine();
if (userinput.Contains("BelowNormal"))
{
thread.Priority = ThreadPriority.BelowNormal;
}
謝謝!我真的很感激快速回復! –
Thx,自從我使用控制檯以來一直是永恆的 –
那麼,如果我輸入'NotBelowNormal',該怎麼辦? –
您可以使用Enum.Parse
,例如使用重載方法與ignoreCase
:
thread.Priority = (ThreadPriority)Enum.Parse(typeof(ThreadPriority),
"belownormal", true);
謝謝!我真的很感激快速回復! –
是它發送一個數字那麼簡單對應於枚舉優先級的值? –
試着用Enum.Parse解析它 – AntLaC