How to kill off a pending APM operation

后端 未结 2 894
余生分开走
余生分开走 2021-01-15 01:27

If you have a pending operation, eg

stream.BeginRead(_buffer, 0, _buffer.Length, _asyncCallbackRead, this);

and you close the stream provi

相关标签:
2条回答
  • 2021-01-15 01:29

    This is not directly supported in the framework. Your best bet is to write a wrapper that spawns a thread and use synchronization primitives like events to signal a cancel request.

    HTH

    Colby Africa

    0 讨论(0)
  • 2021-01-15 01:34

    [Inspired by the chapter on APM in Richter's CLR via C# I decided to see what goodies SO had on the subject and I found this question. I thought Peter had a great question here and did a bit of research -- this is the result]

    Jeffrey Richter in CLR via C# (chapter 27) discusses his AsyncEnumerator class which (supposedly) takes much of the pain away from programming the APM. One of the features of this class (part of his freely available Power Threading Libary) is the ability to cancel asynchronous operations.

    The class can be downloaded from the link above. The page also includes a link to a Yahoo Group Richter set up to provided limited support for the lib.

    He introduces the library in these MSDN articles:

    Simplified APM With The AsyncEnumerator
    More AsyncEnumerator Features

    0 讨论(0)
提交回复
热议问题