是否可以在不暂停执行的情况下在 Visual Studio 2010 中编辑并继续? [英] Is it possible to Edit and Continue in Visual Studio 2010 without pausing execution?

查看:21
本文介绍了是否可以在不暂停执行的情况下在 Visual Studio 2010 中编辑并继续?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近观看了一些 Notch 的 Ludum Dare 直播.他在开发游戏时广泛使用 Eclipse 的热插拔功能.(这里是我所指的视频 http://www.twitch.tv/notch/b/302823358?t=86m30s)

我想用 C# 和 XNA 做同样的事情.幸运的是,Visual Studio 具有编辑并继续功能.但是,我想在渲染代码运行时编辑它,而不是暂停它.

我可以设置 Visual Studio 来做同样的事情吗?我注意到当一个进程中断时中断所有进程有一个复选框.是否可以在另一个线程中设置我的渲染循环,以便在我进行更改时游戏继续渲染?

解决方案

更新:此答案现已可用 作为视频.

<小时>

我一直在努力寻找一种方法来做到这一点.我知道这不能回答你的确切问题.但实际上您正在寻找的是一个工作流,您可以在其中以零(或接近零)延迟进行代码更改,而且我想我已经找到了仅使用 Visual Studio 可以获得的最接近的结果.(因此避免了巨大的工程工作和处理异常"项目).

一旦你想到它,实现这个工作流程的方法实际上非常简单:

使用快捷键!

我想出的第一种方法是使用设置断点的正常编辑并继续方法.只有使用键盘,您才能更快地完成此操作.这仅适用于在循环中调用的代码(例如:绘制/更新).点击你要修改的代码,添加断点(F9),断点几乎马上就被命中,修改你的代码,去掉断点(F9),然后再次运行代码(F5).

这个还不错.您不必使用鼠标点击左侧栏中相对较小的添加断点"目标.但它确实将输入焦点移动到行首,因此您通常必须再次使用鼠标来修复它,然后才能开始编辑.

我想要更快的速度.所以我想出了一个更好的解决方案:

再次使用键盘:按 Ctrl + Alt + Break 以Break All".这几乎立即进入调试器,无需担心设置断点或您要修改的代码是否在循环中运行.这会将编辑器窗口和插入符号焦点更改为执行中断的文档,但您可以通过按 Ctrl + - 为向后导航"立即修复它.>

然后您可以进行编辑,只需按 F5 即可查看它们的效果.您只需使用鼠标一次(或根本不使用)即可选择要开始输入的位置 - 正如您所期望的那样.

诚然Ctrl + Alt + BreakCtrl + -可怕的键组合,用于您希望能够非常快速地完成的事情.要是能按一个键就好了.

如果您拥有完整的 Visual Studio,您可能可以将其转换为宏或加载项.Express 没有这些——所以你能做的最好的事情就是修改你的键绑定(工具、自定义、键盘……)并将它绑定到两个相邻的键,你可以快速连续按下.或者使用外部宏实用程序.

就我个人而言,我已将两个组合键设置为通过设置为鼠标上备用按钮的宏连续按下(您似乎不需要在两者之间延迟).效果相当好 - 因为我通常同时选择文本.稍后我也可能会添加一个键盘宏.

到目前为止,我已经确定了这种方法的两个小缺陷:

  • 当您再次运行应用时,Visual Studio 会为其提供焦点.如果能保持专注就好了.向我的宏添加鼠标左键单击是快速重新编辑代码的部分解决方案.
  • 向后导航"不保留文本选择,只保留插入符号位置.

I recently watched a bit of Notch's Ludum Dare live stream. He uses Eclipse's hotswap feature extensively while he works on his game. (here is a video of what I am referring to http://www.twitch.tv/notch/b/302823358?t=86m30s)

I would like to do the same with C# and XNA. Fortunately, Visual Studio has an Edit and Continue feature. However, I would like to edit my rendering code while it is running instead of pausing it.

Is it possible for me to setup Visual Studio to do the same? I noticed that there is a checkbox for Break all processes when one process breaks. Is it maybe possible to set up my rendering loop in another thread so that the game keeps rendering while I make a change?

解决方案

Update: This answer is now available as a video.


I've been struggling to find a way to do this. I know this doesn't answer your exact question. But really what you are looking for is a workflow where you can make code changes with zero (or near-zero) delay, and I think I've figured out the closest you can get with just Visual Studio. (And therefore avoiding a huge engineering effort and dealing with "abnormal" projects).

The way to achieve this workflow is actually astonishingly simple, once you think of it:

Use shortcut keys!

The first way I came up with is to just use the normal edit-and-continue method of setting a breakpoint. Only by using the keyboard you can do this considerably faster. This only works with code being called in a loop (eg: draw/update). Click the code you want to modify, add a breakpoint (F9), the breakpoint will almost immediately be hit, modify your code, remove the breakoint (F9), and then run the code again (F5).

This is pretty good. You don't have to use the mouse to hit the relatively small "Add breakpoint" target in the left hand column. But it does move the input focus to the beginning of the line, so you generally have to use the mouse again to fix that before you can start editing.

I want something faster. So I came up with a better solution:

Again, using the keyboard: Press Ctrl + Alt + Break to "Break All". This enters the debugger almost instantly, without having to worry about setting a breakpoint or if the code you want to modify is running in a loop. This will change the editor window and caret focus to the document where execution break, but you can then immediately fix it by pressing Ctrl + - for "Navigate Backwards".

Then you can make your edits and simply press F5 to see them in action. You only have to use the mouse once (or not at all) to initially pick where you want to start typing - just as you would expect.

Admittedly Ctrl + Alt + Break and Ctrl + - are horrible key combinations for something you want to be able to do extremely quickly. And it would be better if there was just one key to press.

If you have the full Visual Studio, you could probably turn it into a macro or add-in. Express doesn't have those - so the best you can do is modify your key bindings (Tools, Customise, Keyboard...) and bind it to two keys that are adjacent, that you can press in quick succession. Or use an external macro utility.

Personally I have set up the two key combinations to be pressed in succession (you don't seem to need a delay between the two) by a macro set to a spare button on my mouse. Which works reasonably well - as I'm usually selecting text at the same time. I might add a keyboard macro later too.

So far I've identified two minor pitfalls of this method:

  • When you run the app again, Visual Studio gives it focus. It would be nice if it kept focus. Adding a left mouse click to my macro is a partial solution to quickly re-editing code.
  • "Navigate Backwards" does not retain the text selection, only the caret position.

这篇关于是否可以在不暂停执行的情况下在 Visual Studio 2010 中编辑并继续?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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