使用不带Await的Async命令 [英] Using Async commands without Await

查看:122
本文介绍了使用不带Await的Async命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开始使用异步数据库处理来增强处理,但事情似乎变得相当混乱。顺便说一下,这是在VB中完成的。


首先,使用Await希望你将Async放在子或函数上,这会导致级联一直到Main。似乎应该有更好的方法。无论如何,我正在尝试在执行ExecuteNonQueryAsync时使用Task对象。
然后我可以查询任务而不必使用Await并创建随之而来的所有语法问题。


这似乎有效,除非我开始执行ExecuteNonQueryAsync插入一组行,然后如果我在第一个插入完成之前启动另一个插件来执行另一批插入,则它似乎过早地终止第一个插入。这是正常的
体验吗?我认为使用单独的连接可以解决这个问题。我通过检查以确保第一个任务在启动第二个任务之前已经完成,并且这个工作正常。


我沿着这条线的下一步是启动查询并进行并行处理在查询运行时,然后在完成所有操作后,将并行完成的工作与查询结果相结合。我打算使用DataReader来执行此操作,因为它似乎是
,就像支持Async的选项一样。


这里的区别在于ExecuteReaderAsync返回一个DBDataReader。如果我使用Task而不是await,我没有看到获取DBDataReader的方法。所以我想我会使用任务(of dbDataReader)然后使用await来返回dbDataReader,
然后我遇到问题,我的所有函数都需要Async修饰符一直回到Main。 / p>

所以我的问题是如何在不使用Await的情况下获取从ExecuteReaderAsync返回的dbDataReader?但这导致了其他问题。


  1. 我在等待ExecuteReaderAsync到底是什么?在Await返回dbDataReader之前,它在过程中走了多远?
  2. 考虑到上一个问题,dbDataReader中等待的其他异步操作是什么?由于所有这些操作都具有Async选项,在ExecuteReaderAsync中满足await之前,似乎整个查询可能都不完整。
  3. 在满足Await之前,似乎ExecuteReaderAsync等待查询完成,但不是实际的数据传输,这就是其他Async选项在dbDataReader中的原因。正确吗?
  4. 如果3为真,那么我仍然希望在查询运行时可以自由进行其他并行处理,这就是我不想使用await开始的原因。

所以请指出我的猜测是对还是错,让我知道是否有办法在不使用Await的情况下获取dbDataReader。 / p>



Mike

解决方案


请参考以下链接,了解有关如何处理异步数据序列的一些好主意。


http://blogs.msdn.com/b/pfxteam/archive/2013 /04/03/tasks-monads-and-linq.aspx


I am trying to get started in using async database processing to enhance processing, but things seem to get pretty confusing. This is being done in VB by the way.

First, using Await wants you to put Async on the sub or function, which results in cascading all the way up to Main. Seems like there should be a better way. In any event, I was experimenting with such things as using a Task object set when doing ExecuteNonQueryAsync. I could then query the Task and not have to use Await and create all the syntax issues that go with it.

This seemed to work except that if I began an ExecuteNonQueryAsync to insert a group of rows, then if I initiate another one to do another batch of inserts before the first one is complete, it seems to terminate the first one prematurely. Is this the normal experience? I presume using separate connections would take care of this. I took care of it by checking to be sure the first task was done before initiating the second and this worked.

My next step along this line was going to initiate a query and do parallel processing while the query ran, and then after all was done, combine the work done in parallel with the query results. I was going to use a DataReader to do this because it seemed like the option that supported Async.

The difference here is that the ExecuteReaderAsync returns a DBDataReader. If I use Task instead of await, I don't see a way to get at the DBDataReader. So I thought I would use the task (Of dbDataReader) then use await on it to return the dbDataReader, but then I run into the problem with all my functions needing the Async modifier all the way back up to Main.

So my question is how I can get at the dbDataReader returned from ExecuteReaderAsync without using Await? But this leads to other questions.

  1. What exactly am I waiting for with ExecuteReaderAsync? How far along in the process does it go before the Await can return a dbDataReader?
  2. Considering the previous question, what are the other Async operations waiting on in dbDataReader? With all these operations having Async options, it would seem that the entire query may not be complete before the await is satisfied in ExecuteReaderAsync.
  3. It may seem that ExecuteReaderAsync waits for the query to complete before satisfying the Await, but not the actual transmission of data which is why the other Async options are in the dbDataReader. Correct?
  4. If 3 is true, then I would still like to be free for other parallel processing while the query is being run which is why I did not want to use await to begin with.

So please point out where my guesses are right or wrong, and let me know if there is a way to get at the dbDataReader without using Await.


Mike

解决方案

Hi,

please refer to following link for some great ideas on how to process asynchronous data sequences.

http://blogs.msdn.com/b/pfxteam/archive/2013/04/03/tasks-monads-and-linq.aspx


这篇关于使用不带Await的Async命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆