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

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

问题描述

我最近观看了Notch的Ludum Dare现场直播.在进行游戏时,他广泛使用Eclipse的热插拔功能. (以下视频是我指的 http://www.twitch.tv/notch/b/302823358?t = 86m30s )

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

是否可以将Visual Studio设置为执行相同操作?我注意到有一个Break all processes when one process breaks复选框.也许可以在另一个线程中设置我的渲染循环,以使游戏在我进行更改时保持渲染?

解决方案

更新:该答案现已可用

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

使用快捷键!

我想到的第一种方法是只使用设置断点的常规编辑并继续方法.只有使用键盘,您才能更快地完成此操作.这仅适用于在循环中调用的代码(例如:绘制/更新).单击您要修改的代码,添加一个断点( F9 ),该断点几乎立即被击中,修改您的代码,删除breakoint( F9 ),然后再次运行代码( F5 ).

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

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

再次

使用键盘:按 Ctrl + Alt + Break 可以全部破坏".这样几乎可以立即进入调试器,而不必担心设置断点或要修改的代码是否在循环中运行.这将更改编辑器窗口,并将插入符号集中到执行中断的文档上,但是您可以通过按 Ctrl + -进行向后导航"立即修复它.

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

公认的 Ctrl + Alt + Break Ctrl + -可怕的组合键,可以快速完成某些任务.如果只按一个键,那会更好.

如果您拥有完整的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天全站免登陆