开发者

IsCompletedSynchronously for the RegisterasyncTask

I am using RegisterAsyncTask to do some IO bound operation in aspx page. I have 2 question regarding the same.

1) What happens if I perform the IO operation in OnBeginEvent and the BeginfXXX retrun synchronosuly (IAsyncResult.CompletedSynchronouslt = true). Will the OnEnd handler be invoked.

I just tested it by creating a mock IAsyncResult implemenation, and it seems neither the OnEnd handler is invoked and neither do the page rendering is completed (till the timeout event occurs). What should be done in such cases?

开发者_开发问答

2) The question is something in line to the first one. Let say I register my async task. In the ONBegin handler, I perform some pre-Steps and depending on the pre-validation, I just need to return from the Onbegin event. Is it possible to return from the OnBeginEventHandler, with a null IAsyncResult (or mock). I tried using the same approach above and it doesn't seems to work.

Any help will be appreciated

Thanks

Kunal


1) It depends on how you are implementing your begin method. You have to be able to invoke the callback, whether you have completed the operation synchronously or not, as the caller might depend on the callback being called.

2) No. You must return a valid IAsyncResult. If you have a value that you want to return from the BeginXXX method, you should save it, call the callback and return it from the EndXXX method, while returning a valid IAsyncResult object from the BeginXXX method.

Jeffrey Richter's async enumerator will help you implement the Begin/End pattern very easily. You should take a look at this: http://msdn.microsoft.com/en-us/magazine/cc546608.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜