In a WPF app I have a pool of threads (each thread is a call to a REST webservice returning base64 image) that I'd like to "control" much precisely.
在一个WPF应用程序中,我有一个线程池(每个线程都是对返回base64映像的REST webservice的调用),我想要更精确地“控制”这个线程池。
These threads are async and I'd like to be able to suspend/resume each of them.
这些线程是异步的,我希望能够挂起/恢复它们。
-
Use something like a CancellationToken is not an option I guess because each thread is doing just a call and waiting for the answer.
我认为使用取消令牌之类的东西不是一个选项,因为每个线程只执行一个调用并等待答案。
-
I just saw that in the class Thread => Suspend & Restart are obsolete/deprecated.
我刚才看到在类线程=>挂起和重启已经过时/不赞成。
So if someone has any suggestion?
如果有人有什么建议?
Thanks by advance.
提前谢谢。
1 个解决方案
#1
0
So the type of control you are looking for with your threads isn't exactly feasable because of the nature of threads. Thread execution is queued up by the OS and it's scheduler. This means that you have no control as to when the thread will be actively running. However, fibers are similar to threads with the difference that the application is responsible for scheduling and switching threads. Fibers are idealized as co-routines in mono and the win32 library has some support for them. The .net framework doesn't provide much support for it though.
因此,由于线程的性质,您正在寻找的控制类型并不是完全可以实现的。线程执行由操作系统排队,它是调度程序。这意味着您无法控制线程何时将在活动中运行。然而,纤程与线程相似,不同之处在于应用程序负责调度和交换线程。在mono中,纤程被理想化地化为协例程,win32库对它们有一些支持。但是。net框架并没有提供太多的支持。
Some people here in the community have been asking about fibers but their searches have been mostly fruitless. SO post
社区里的一些人一直在问纤维的问题,但他们的搜索大多是徒劳的。所以文章
This answer may lead you in a direction that may help you on your journeys. It mentions creating you own scheduler for the parallel task library.
这个答案可能会引导你走向一个可以帮助你在旅途中前进的方向。它提到为并行任务库创建自己的调度程序。
I didn't explore the concept much as i haven't had the need for it yet, but the yield return program design seems to be an alternative.
我没有深入研究这个概念,因为我还不需要它,但是收益率回报方案设计似乎是一种选择。
#1
0
So the type of control you are looking for with your threads isn't exactly feasable because of the nature of threads. Thread execution is queued up by the OS and it's scheduler. This means that you have no control as to when the thread will be actively running. However, fibers are similar to threads with the difference that the application is responsible for scheduling and switching threads. Fibers are idealized as co-routines in mono and the win32 library has some support for them. The .net framework doesn't provide much support for it though.
因此,由于线程的性质,您正在寻找的控制类型并不是完全可以实现的。线程执行由操作系统排队,它是调度程序。这意味着您无法控制线程何时将在活动中运行。然而,纤程与线程相似,不同之处在于应用程序负责调度和交换线程。在mono中,纤程被理想化地化为协例程,win32库对它们有一些支持。但是。net框架并没有提供太多的支持。
Some people here in the community have been asking about fibers but their searches have been mostly fruitless. SO post
社区里的一些人一直在问纤维的问题,但他们的搜索大多是徒劳的。所以文章
This answer may lead you in a direction that may help you on your journeys. It mentions creating you own scheduler for the parallel task library.
这个答案可能会引导你走向一个可以帮助你在旅途中前进的方向。它提到为并行任务库创建自己的调度程序。
I didn't explore the concept much as i haven't had the need for it yet, but the yield return program design seems to be an alternative.
我没有深入研究这个概念,因为我还不需要它,但是收益率回报方案设计似乎是一种选择。