I chose to return Task<T>
and Task
from my objects methods to provide easy consumation by the gui. Some of the methods simply wait for mutex of other kind of waithandles . Is there a way to construct Task
from WaitHandle.Wait()
so that I don't have to block one treadpool thread for that.
相关问题
- How to let a thread communicate with another activ
- IPAddress.[Try]Parse parses 192.168 to 192.0.0.168
- Why it isn't advised to call the release() met
- ThreadPoolTaskScheduler behaviour when pool is ful
- Custom TaskScheduler, SynchronizationContext?
相关文章
- How do do an async ServiceController.WaitForStatus
- Difference between Thread#run and Thread#wakeup?
- Java/Spring MVC: provide request context to child
- Threading in C# , value types and reference types
- RMI Threads prevent JVM from exiting after main()
- Efficient signaling Tasks for TPL completions on f
- Async task does not work properly (doInBackground
- Android, Volley Request, the response is blocking
As noted by @gordy in the comments of the accepted answer of Sergey Teplyakov, MSDN proposes an implementation with unsubscription of the registered WaitHandle.
I slightly modified it here to support the result of the callback: if the registration has timed out, the task return false. If the signal has been received, the task return true:
Usage is same as the original answer:
There is a way to do this: you can subscribe to WaitHandle using ThreadPool.RegisterWaitForSingleObject method and wrap it via TaskCompletionSource class:
Usage: