Skip to content
This repository was archived by the owner on Apr 1, 2022. It is now read-only.

Conversation

@TyrWang
Copy link

@TyrWang 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();
Copy link
Owner

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 就好了?

Copy link
Author

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 的情況下應該差不多

@renewal-wu
Copy link
Collaborator

https://msdn.microsoft.com/en-us/library/cc189907(v=vs.110).aspx
Blocks the current thread until the current WaitHandle receives a signal, using a 32-bit signed integer to specify the time interval in milliseconds.

UI thread 不會因為 mre.WaitOne(5000); 而被 blocked 嗎??

@renewal-wu
Copy link
Collaborator

改用 Task 會不會比較安全??

@TyrWang
Copy link
Author

TyrWang commented Nov 20, 2017

原本的想法是沒有預期要在資訊還沒完整取回前就讓程序往下走的, 更何況這個 Init() 應該是在程序剛啟用階段, 甚至 UI 還沒顯示以前囉

@renewal-wu
Copy link
Collaborator

我比較好奇不改成 Task 讓 thread 不至於被 blocked 的原因是??

@TyrWang
Copy link
Author

TyrWang commented Nov 20, 2017

當然不要 block UI thread 可以讓 Init() 在任何時候被呼叫都不會有太多顧忌

不過我想在使用者對 UI 做操作以前在可接受的等待時間內把資訊取回來,
不然如果使用者在我取回資訊就開始操作也可能導致錯誤的資料

@renewal-wu
Copy link
Collaborator

OK
worst case 會卡 UI 五秒看起來有點可怕就是了...

@TyrWang
Copy link
Author

TyrWang commented Nov 20, 2017

我 push 上了新的 code, 改用 Task, 這樣應該就不會有卡住 UI thread 的疑慮了
麻煩幫我想一下這樣在 DeviceInformationService() 底下的 task 還沒完成前 call TrackEvent() 會不會出問題
我想了一下應該是不會, 畢竟 constructor 還是會走完, UserAgent 可以完整組出來

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants