Wednesday, October 12, 2005

Microsoft Visual Studios 2005 Team System, Episode IV (Microsoft Visual C# 2.0 new Features Part A)

Now I'll resume the Visual Studio 2005 Articles, but I'll put one or two new features in each new article to stop it from being to large.

Let's begin.

One of the most amazing features which come with C# 2.0, is the enabling of edit and continue in debugging mode, in this article, we'll talk about what's edit and continue, how it's working, and its limitations inside C# 2.0, for the full article, visit: http://msdn.microsoft.com/vcsharp/default.aspx?pull=/library/en-us/dnvs05/html/edit_continue.asp


What is edit and continue?

Edit and Continue (hereafter referred to as E&C) is a new debugging feature introduced in Visual C# 2005, it was used by VC++ developers since early VC++ editors.
It allows you to make changes to the code while an application is being debugged and to apply the code changes without having to end execution, rebuild, and run the application again.


But how it could make your life easier?!

Imagine you're making something like a complete Game Engine, or a huge 3D game, and as you know debugging such applications is like hell, now imagine after 20 pr 30 min of full debugging, you discovered that you need to change something in your code, but Ohh my god, I must stop the debugging and restart it again, so all the time I passed in the debugging (the 30 min) is over now, and furthermore, I may lost the exception which I had already caught if I tried to restart it again, so what shall I do?!!
Now this is why you should use edit and continue, because now you're not forced to stop and restart the debugger again, it'll just get the edits you made, inject it to the code inside memory and here you're debugging the application after being changed without restarting it, isn't it amazing ;)


How does edit and continue work?!

Though E&C is simple to use, the CLR and the compiler have to work together to do some heavy lifting in the background. When a file is edited in the IDE during a debugging session, the compiler first checks whether the change is allowed or not. If it is not possible to perform that change, you'll see a dialog box like the one in Figure 1.

Figure 1. Message box shown when you make a change that is not allowed



Clicking the Edit Code button takes you back to the debugging session to allow you to fix the errors that won't allow the debugging session to continue. You might choose this option if the errors that didn't allow E&C to continue were build errors. . Clicking the Stop Debugging button ends the current debugging session and reverts back to design mode. You would choose this option if the errors detected are changes that you need to make. The compiler supplies delta-IL and delta-metadata, which is used to replace parts of the existing IL and metadata in memory. Delta-IL and delta-metadata simply refers to the gap used to insert the edited code. If the edited methods have been JIT-ed into native x86 code, they are replaced with new x86 code.

Limitations of Edit and Continue:

The rule of thumb for making E&C changes is that you can change virtually anything within a method body, so larger scope changes affecting public or method level code are not supported. Some examples of such unsupported changes are:
· Changing the name of a class.
· Adding or removing method parameters.
· Adding public fields to a class.
· Adding or removing methods.


That's all for today, next time we'll talk about Generics the new feature in C# 2.0 which mimics C++ templates but in different way.
Catch you later.....

1 comment:

Anonymous said...

Thank you very much
waiting for the Generics...