-
Notifications
You must be signed in to change notification settings - Fork 2
put the whole progress in a thread and only wait for 5 seconds #16
base: master
Are you sure you want to change the base?
Conversation
TyrWang
commented
Nov 17, 2017
- put ManagementObject in a "try catch" to prevent a ManagementException cause by WMI error
- give SystemManufacturer and ModelName an init-value
- put ManagementObject in a "try catch" to prevent a ManagementException cause by WMI error - give SystemManufacturer and ModelName an init-value
| SystemManufacturer = $"{process["Manufacturer"]}"; | ||
| ModelName = $"{process["Model"]}"; | ||
| } | ||
| mre.Set(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://dotblogs.com.tw/yc421206/2011/01/05/20609
好奇怎麽不用 AutoResetEvent 就好了?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://stackoverflow.com/a/7800138/2753638
我當初是看這一篇
看了一下這兩個 class 感覺在只有一個 thread 的情況下應該差不多
|
https://msdn.microsoft.com/en-us/library/cc189907(v=vs.110).aspx UI thread 不會因為 mre.WaitOne(5000); 而被 blocked 嗎?? |
|
改用 Task 會不會比較安全?? |
|
原本的想法是沒有預期要在資訊還沒完整取回前就讓程序往下走的, 更何況這個 Init() 應該是在程序剛啟用階段, 甚至 UI 還沒顯示以前囉 |
|
我比較好奇不改成 Task 讓 thread 不至於被 blocked 的原因是?? |
|
當然不要 block UI thread 可以讓 Init() 在任何時候被呼叫都不會有太多顧忌 不過我想在使用者對 UI 做操作以前在可接受的等待時間內把資訊取回來, |
|
OK |
|
我 push 上了新的 code, 改用 Task, 這樣應該就不會有卡住 UI thread 的疑慮了 |