G3官方请说中文,想知道

I wrote the following WPF sample app in VB.NET 14 using .NET 4.6.1 on VS2015.1:
Class MainWindow
Public Sub New()
InitializeComponent()
Private Async Sub Button_Click(sender As Object, e As RoutedEventArgs)
MessageBox.Show("Pre")
Using window = New DisposableWindow()
window.Show()
For index = 1 To 1
Await Task.Delay(100)
MessageBox.Show("Post")
Class DisposableWindow
Inherits Window
Implements IDisposable
Public Sub Dispose() Implements IDisposable.Dispose
Me.Close()
MessageBox.Show("Disposed")
The sample below produces the following output:
Debug mode: Pre, Disposed, Post
Release mode: Pre, Post
This is strange. Why would Debug mode execute this code differently than Release mode...?
When I change the using block to a manual try/finally block, the call to window.Dispose() even throws a NullReferenceException:
Dim window = New DisposableWindow()
window.Show()
For index = 1 To 1
Await Task.Delay(100)
window.Dispose()
And even more strange stuff: When the for-loop is excluded, the sample works perfectly. I've only let the For-loop run once, to specify the minimum amount of loops the produce the issue. Also feel free to replace the For-loop with a While-loop. It produces the same behavior as the For-loop.
Using window = New DisposableWindow()
window.Show()
Await Task.Delay(100)
Now you might think: 'That is strange!'. It gets even worse.
I've also made the exact same example in C# (6), where it works perfectly. So in C# both Debug and Release mode result in 'Pre, Disposed, Post' as output.
The samples can be downloaded here:
I'm pretty stumped at this point. Is this a bug in the VB.NET stack of .NET Framework? Or am I trying to accomplish something strange, which by luck seems the work in C# and partially in VB.NET?
Did some more test:
Disabling compiler optimizations in VB.NET for Release mode, makes it behave like Debug mode (as expected, but wanted to test it, just in case).
The issue also happens when I target .NET 4.5 (the earliest version where async/await became available).
This has since been fixed. Public release is planned for version 1.2, but the latest version in the master branch should contain the fix.
解决方案 I'll write this one up, this Roslyn bug is exceedingly nasty and liable to break a lot of VB.NET programs.
In a very ugly and difficult to diagnose way.
The bug is pretty hard to see, you have to look at the generated assembly with a decompiler.
I'll describe it at break-neck speed.
The statements in the Async Sub get rewritten into a state machine, the specific class name in your snippet is VB$StateMachine_1_buttonClick.
You can only see it with a decent decompiler.
The MoveNext() method of this class executes the statements in the method body.
This method is entered multiple times while your async code runs.
Variables used by MoveNext() need to be captured, turning your local variables into fields of the class.
Like your window variable, it will be needed later when the Using statement ends and the Dispose() method needs to be called.
The name of this variable in the Debug build is $VB$ResumableLocal_window$0.
When you build the Release build of your program, the compiler attempts to optimize this class and fumbles badly.
It eliminates the capture and makes window a local variable of MoveNext().
This is horribly wrong, when execution resumes after the Await, that variable will be Nothing.
And thus its Dispose() method won't be called.
This Roslyn bug has a very large impact afaict, it will break any VB.NET code that uses the Using statement in an Async method where the statement body contains an Await.
This is not easy to diagnose, a missing Dispose() call very often goes undetected.
Except in a case like yours where it has a very visible side-effect.
There must be lots programs running in production that have this bug right now.
Side-effect is that they'll run "heavy", consuming more resources than necessary.
The program can fail in many hard to diagnose ways.
There is a temporary workaround for this bug, be sure to never deploy the Debug build of your VB.NET app, that has other problems.
Turn off the optimizer instead.
Select the Release build and use Project > Properties > Compile tab > Advanced Compile Options > untick the "Enable optimizations" checkbox.
Yikes, this is bad.
本文地址: &
我写了下面的WPF示例应用程序在VB.NET 14使用.NET 4.6.1上VS2015.1: 类主窗口
的Public Sub New()
的InitializeComponent()
私人异步子Button_Click(发送者为对象,E为RoutedEventArgs)
MessageBox.Show(“pre”)
使用窗口=新DisposableWindow()
window.Show()
对于指数= 1:1
等待Task.Delay(100)
MessageBox.Show(“邮报”)
类DisposableWindow
实现IDisposable
公用Sub的Dispose()实现IDisposable.Dispose
Me.Close()
的MessageBox.show(「出售」)
末级末级 下面的示例产生下面的输出:调试模式:pre,处置,邮政 Release模式:pre,邮政这是奇怪的。为什么会调试模式不同执行此code比Release模式...?在我的使用块更改为手动try / finally块,调用window.Dispose()甚至抛出一个NullReferenceException: 昏暗的窗口=新DisposableWindow()尝试
window.Show()
对于指数= 1:1
等待Task.Delay(100)
下一个最后
window.Dispose()结束Try 和更奇怪的东西:当for循环被排除在外,样品完美的作品。我只让for循环运行一次,以指定产生的问题环路的最低金额。还随意更换for循环与while循环。它产生相同的行为for循环。作品: 使用窗口=新DisposableWindow()
window.Show()
等待Task.Delay(100)使用完 现在你可能会想:“这是奇怪!”。它变得更糟。我也用C#(6),它完美的作品做完全一样的例子。因此,在C#Debug和Release模式导致'pre,处置,邮政作为输出。样品可以在这里下载:
我在这一点难倒pretty。这是.NET Framework的VB.NET堆栈中的错误?还是我试图完成一些奇怪的事情,它通过运气似乎在C#和部分VB.NET中的工作? 编辑: 做了一些更多的测试:禁用编译器优化在VB.NET的发布模式,使得它表现得像调试模式(如预期,但要测试它,以防万一)。问题还当我面向.NET 4.5(其中,异步/的await成为可用的最早版本)发生。 更新: 这已经被修复。公开发行计划于1.2版本,但在主分支的最新版本应该包含的修补程序。请参阅: &
扫一扫关注官方微信A.& 配置细节
使用#include &unordered_map&替代&hash_map&
这个是c++标准建议的,没啥好说的
使用#include &directxmath.h&替代&xnamath.h&
注意:如不想修改原xnamath代码,则需在包含directxmath.h之前定义_XM_NO_INTRINSICS_宏标志,以与原xnamath代码兼容
然而,_XM_NO_INTRINSICS_标志将指示directxmath不使用SSE/SSE2等增强型指令集,因此其数学实现极慢。如果想速度快,还是得去掉该标志,并相应地重写原xnamath代码为妥
去除d3dx11,不再使用任何legacy DX SDK中的头文件或lib,坚持使用win SDK 8.0
这个是保障vs2015能够顺利编译链接、并且避免后继编译链接配置混乱的关键
去除项目设置中legacy DX SDK相关的include、lib路径定义
去除链接设置中legacy DX SDK相关的lib依赖,包括d3dx11.lib、dxerr.lib等;这些lib不要写在项目工程的linker inputs里面,用#pragma comment写在头文件里面
针对d3dx11,使用DirectXTex库来进行替代;DirectXTex lib需用vs2015重新编译
注意:DirectXTex库的API较d3dx11的API形式上变化极大,如纹理加载API等。所有d3dx11相关的代码均可能需要重写,这块是最大的工作量
针对dxerr,可找到其源码.cpp/h,将其直接包含进项目,一起编译
注意:不能再使用legacy dx sdk中的dxerr.lib,因其使用了过时的库,因此在vs2015中无法link
在直接包含编译dxerr.h/cpp的同时,可能会碰到若干预定义标志重定义,得自己手工调整一下
在#include &dxerr.h&之前,需添加#include &Mmreg.h&定义
针对effect11,其lib需用vs2015重新编译
为提升STL调试时效率,可将_HAS_ITERATOR_DEBUGGING、_SECURE_SCL编制标志设置为0,关闭迭代子调试功能;注意:在编译directxTex、effect11等外部lib时,也必须设置上述标志,否则无法link
针对d3d_compiler,可直接使用win sdk 8自带的lib
注意:d3d_compiler.lib会运行时调用d3dcompiler_XX.dll(xx是版本号),需要将这个dll拷贝到系统目录或程序当前目录下,以便运行时能够加载
注意:这个dll在win sdk 8的bin目录里面有,但有x32、x64两个版本,在拷贝dll时千万别拷错了版本,否则运行时崩溃(0xc000007b Error)
B.&& 参考文献
阅读(...) 评论()&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!&&国之画&&&& &&
版权所有 京ICP备号-2
迷上了代码!vs2015 查找替换-学网-提供健康,养生,留学,移民,创业,汽车等信息
vs2015 查找替换
以文本文档方式打开它。(我用的是sublime text 2,我认为是款代替记事本的不错工具,性... vs2012是v110,vs2010是v100,vs2013则是v120。我想先不去项目文件里查看,也许在加...export难以实现,主要有2个原因:(1)export依赖于Koenig查找(2)从概念上来说,export要求... 不只是vs2015,现在支持export的编译器也是少数。建议你选择替代方案(例如借助重载、..."入站规则"。 在入站规则列表中,查找用于活动网络的所有网络发现规则。(例如,查找所... 使用"Visual Studio 命令提示符"窗口构建驱动程序 打开"适用于 VS2015 的开发人员命...上商城等(电子城假-货太多,别相信防伪查找) 硬盘 西部数据 蓝盘500G WD5000AAKX ... 6750恒金1G GDDR5 600 游戏(game)表现出色,主流3D网络游戏随便。替换5750,性能...反向渐进式搜索 Ctrl+F: 查找 Ctrl+Shift+F: 在文件中查找 F3: 查找下一个 Shift+F3: 查找上一个 Ctrl+H: 替换 Ctrl+Shift+H: 在文件中替换 Alt+F12: 查找符号(列出所有查找结果) C... 桀、纣残暴失民心;商汤和武王仁义之举得民心;任用贤人(伊尹、姜尚),联合周边小国。 三、夏商周的政治 1、启:继承父位,成为夏朝第二代国王,从此,世袭制代替了禅让制,"公天...以方便操作人员日常保存、查找等使用。 三、作战支援设备更先进。根据计划,美海军... 首艘航母"CVN78"将于2008年开始正式建造,计划于2015年投入服役,以取代美海军的第...影响深远的札甲。到了秦代,札甲的长方形甲片已经日趋细小,从而更贴身和灵活,同时编缀技术也出现了阴线和阳线的区分。进入炼钢业蓬勃的西汉,铁甲胄逐渐取代了皮甲胄的...
您可能还关注:&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
大类导航: |

我要回帖

更多关于 请说 的文章

 

随机推荐