Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Modifying my own code while it's running


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 DvDmanDT   GDNet+   -  Reputation: 1300

Like
0Likes
Like

Posted 03 January 2014 - 08:23 PM

Hi everyone, has anyone here successfully managed to rewrite their C#/.NET code while it's running?

 

What I want to do in particular is to wrap a method in a try..finally block with SomeDebugClass.MethodEntry() and SomeDebugClass.MethodExit() calls. Any ideas?



Sponsor:

#2 frob   Moderators   -  Reputation: 29877

Like
2Likes
Like

Posted 03 January 2014 - 08:46 PM

Visual Studio has an "edit and continue" option that you might be able to use.

 

When you have the proper compiler options set, you pause the code in the debugger, modify the code within a function, and resume execution. Visual Studio will hot-patch the program and run your new, modified code.


Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.


#3 Telastyn   Crossbones+   -  Reputation: 3754

Like
1Likes
Like

Posted 03 January 2014 - 09:07 PM

You're better off using an aspect oriented programming framework like PostSharp to inject these things during a build step rather than at runtime. I'm not sure how viable ubiquitous runtime modification of a loaded assembly is.

#4 DvDmanDT   GDNet+   -  Reputation: 1300

Like
0Likes
Like

Posted 03 January 2014 - 09:11 PM

I should probably have been slightly more specific with my requirements. :)

 

I want to do this with code in the same application that is to be modified. I want to do highly localized instrumented profiling in a deployed or semi-deployed application/game. For example, a beta-tester is running my game which normally runs fine, but all of a sudden, he gets a serious framerate drop. Now I want a way to figure out what is causing it. Using dynamically inserted BeginSection and EndSection calls would be extremely nice and useful in this case.



#5 Telastyn   Crossbones+   -  Reputation: 3754

Like
2Likes
Like

Posted 03 January 2014 - 09:24 PM

Enh, up I imagine the runtime modification would screw up your profiling more than simply including it always (in beta) and turning on logging when needed. When done judiciously, it won't substantially impact performance but still give you plenty of instrumentation to identify issues.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS