什么是铁轨堆叠?(What is rails stack?)
我已多次遇到rails stack术语,但我仍然无法得到人们称之为rails stack的内容还有什么是对rails堆栈的了解 ?
I've run into rails stack term for many times but I still can't get what do people call rails stack furthermore what is a good knowledge of the rails stack?
原文:https://stackoverflow.com/questions/8590672
最满意答案
作为一般规则,只要异步操作的区域是自包含且独立的 ,您应该使用
ConfigureAwait(false)
- 实际上这样做对于减少开销和瓶颈非常重要。 库代码通常不需要知道调用上下文。 但是, 使用代码(例如winforms,MVC等)通常需要返回到适当的上下文 ,因此不应使用ConfigureAwait(false)
。 例如:async Task SomeUXCodeAsync() { var data = await GetSomeDataAsync(); // note no ConfigureAwait(false) // not shown: use "data" } async Task<Foo> GetSomeDataAsync() { using(var conn = CreateConnection()) { await conn.OpenAsync().ConfigureAwait(false); ... int result = await cmd.ExecuteNonQueryAsync().ConfigureAwait(false); ... return ... } }
上面的场景非常典型和常见, 但它比这更复杂 - 例如,评论中的
TransactionScope
示例涉及数据相关代码可能需要了解调用上下文的示例。 但细微差别:只要消费代码记住不要忽略呼叫上下文,你通常会回到正确的位置。 对不起,这有点模糊和毛茸茸,但是:遗憾的是,这种情况通常适用于呼叫环境。As a general rule, as long as a region of async operations are self contained and independent, you should be fine using
ConfigureAwait(false)
- and indeed doing so can be important to reduce overheads and bottlenecks. The library code usually doesn't need to know about the call-context. However, consuming code (such as winforms, MVC, etc) usually needs to get back to the appropriate context, so should not useConfigureAwait(false)
. For example:async Task SomeUXCodeAsync() { var data = await GetSomeDataAsync(); // note no ConfigureAwait(false) // not shown: use "data" } async Task<Foo> GetSomeDataAsync() { using(var conn = CreateConnection()) { await conn.OpenAsync().ConfigureAwait(false); ... int result = await cmd.ExecuteNonQueryAsync().ConfigureAwait(false); ... return ... } }
The above scenario is pretty typical and common, but it is more complex than that - the
TransactionScope
example from the comments touches on examples where the data related code might need to know about the call context, for example. But nuance aside: as long as the consuming code remembers not to ignore the call context, you'll usually end up back at the right place. Sorry this is a little vague and woolly, but : sadly that's kinda the case generally for the call-context.
相关问答
更多-
ADO.NET记录导航(ADO.NET record navigation)[2022-09-27]
没有必要回到过去的糟糕时光。 如果您可以提供伪代码示例,我可以为您翻译为vb.net。 这是一种通用的方法。 Dim ds as DataSet 'populate your DataSet' For each dr as DataRow in ds.Tables().Rows 'Do something with the row' Next 按编辑1:用户将导航结果,而不是查询。 所以你要做的是a)得到结果并只向他们显示ds.Tables.Row()的当前rowinde ... -
使用ADO.Net SQLConnection对象ConfigureAwait(false)(ConfigureAwait(false) with ADO.Net SQLConnection object)[2022-01-15]
作为一般规则,只要异步操作的区域是自包含且独立的 ,您应该使用ConfigureAwait(false) - 实际上这样做对于减少开销和瓶颈非常重要。 库代码通常不需要知道调用上下文。 但是, 使用代码(例如winforms,MVC等)通常需要返回到适当的上下文 ,因此不应使用ConfigureAwait(false) 。 例如: async Task SomeUXCodeAsync() { var data = await GetSomeDataAsync(); // note no Config ... -
从MATLAB调用ADO.NET(Invoking ADO.NET from MATLAB)[2021-12-03]
我无法在MATLAB中重现该问题。 您正在使用哪个版本的MATLAB? >> version ans = 7.9.1.705 (R2009b) Service Pack 1 >> NET.addAssembly('System.Data'); sqlconn = System.Data.SqlClient.SqlConnection(); sqlconn.State sqlcmd = System.Data.SqlClient.SqlCommand() ans = Closed ... -
除了John回答之外,我还强烈建议你开始将你的SqlConnection和SqlCommand放在using()块中 - 这样可以保证它们在生命周期结束时被处理掉并帮助避免错误。 而不是 SqlConnection con = new SqlConnection(); con.ConnectionString = connectString; con.Open(); SqlTransaction tr = null; tr = con.BeginTransaction(); ...
-
你的假设是正确的。 SqlXml的构造函数将XmlReader的内容存储在内存流中。 它不包含对传入的XmlReader的引用。 反编译的SqlXml构造函数: public SqlXml(XmlReader value) { if (value == null) { this.SetNull(); return; } this.m_fNotNull = true; this.firstCreateReader = true; ...
-
很一般的问题,但有些想法。 性能: 只要所有开发人员都有线索,简单的SqlCommand和DataReader在性能方面会明显加快。 使用.net 4.5和EF 5,似乎EF将获得良好的性能提升,但普通的SQL总是会更快。 请看这里的一些数字: http : //blogs.msdn.com/b/adonet/archive/2012/02/14/sneak-preview-entity-framework-5-0-performance-improvements.aspx 普通的ADO.NET也支持异步模 ...
-
ADO.NET连接池及其对AutoClose = True的影响(ADO.NET Connection Pooling and implications for AutoClose = True)[2023-03-10]
第一个问题,为什么数据库设置为自动关闭? 有效场景包括多租户托管和Express实例,但othar比您的数据库不应设置为自动关闭。 连接池将维护在SQL Server 实例上打开的会话。 会话将保留对当前数据库的引用,从而防止其自动关闭。 如果您的场景涉及单个应用程序数据库,那么所述数据库不应处于自动关闭状态(不是多租户,数千个数据库,场景)。 如果你的场景涉及数千个数据库,那么你的应用程序不应该让它们保持打开状态,除此之外它不能让它们全部打开。 我认为在你的情况下适当的行动是将数据库设置为自动关闭关闭 。 ... -
这里问题的一个部分是ADO.NET是一个抽象的提供者模型。 我们不知道具体实现(特定的ADO.NET提供者)在处理方面需要什么。 当然,我们可以合理地假定需要处理连接和交易,但命令? 也许。 读者? 可能的原因很大程度上是因为其中一个命令标记选项允许您将连接的生命周期与读取器相关联(因此连接在读取器关闭时关闭,这应该在逻辑上延伸到处置)。 总的来说,我认为这可能很好。 大多数情况下,人们不会手工搞乱ADO.NET,任何ORM工具(或者微型ORM工具,比如“Dapper”)都可以为您解决这个问题,而无需担心。 ...
-
从这里 : 与Finalize不同,开发人员应明确调用Dispose以释放非托管资源。 实际上,您应该在实现它的任何对象上显式调用Dispose方法,以释放对象可能持有引用的任何非托管资源。 SqlConnection , SqlCommand , SqlDataReader等...都实现了IDisposable 。 如果将所有这些实例括在Using块中,则会自动调用Dispose ,关闭连接,您不必担心这样的问题。 启动Reflector并自己查看:( SqlConnection.Dispose ) pr ...
-
使用EF db.Add(); 或者db.SaveChanges或任何其他集成的EF方法,ORM(对象关系映射器),在本例中为EF,将使用ADO.NET(因此EF将使用ADO.NET打开数据库连接,EF将使用“SQL查询”创建ADO.NET,...)。 当然,您可以使用ADO.NET方法自己完成所有这些操作,这些方法有时可以提高查询的性能,但通常需要更多的代码编写。 但一般来说,当你使用EF时,你也使用ADO.NET,只有它在EF方法中实现。 When you use EF db.Add(); or db.S ...