A pattern to pause/resume an async task?

前端 未结 5 1392
耶瑟儿~
耶瑟儿~ 2020-11-28 09:12

I have a mostly IO-bound continuous task (a background spellchecker talking to a spellcheck server). Sometimes, this task needs to be put on hold and resumed later, dependin

5条回答
  •  误落风尘
    2020-11-28 10:08

    AsyncManualResetEvent is exactly what you need, considering how messy your current code is. But a slightly better solution would be to use another approach from Stephen Toub: PauseToken. It works similarly to AsyncManualResetEvent, except its interface is made specifically for this purpose.

提交回复
热议问题