How to cancel an asynchronous call?

前端 未结 3 1459
长情又很酷
长情又很酷 2021-02-07 05:27

How to cancel an asynchronous call? The .NET APM doesn\'t seem to support this operation.

I have the following loop in my code which spawns multiple threads on the Threa

3条回答
  •  情歌与酒
    2021-02-07 06:27

    If you're lookin for a "TerminateAsnyc" method, you won't find one. Therefore, no, there's probably no elegant way while using Control.BeginInvoke/EndInvoke. Thus, I'd put the boolean flag on the UI thread and have the delegate being executed asynchronously check that flag periodically while it's executing.

    However, you might check into using background worker threads.

提交回复
热议问题