none
C# 2019 optimizing code - slows everything down RRS feed

  • Question

  • I'm running C#2019 and while I'm debugging I often set a variable (that is normally randomly set) to a specific value

    like here :

    enuMagister_CorrectionType eCorrection;
    do
    {
        eCorrection = (enuMagister_CorrectionType)(cRND.getInt(0, (int)enuMagister_CorrectionType._numCorrections));
    } while (eCorrection == enuMagister_CorrectionType._numCorrections);
    
    eCorrection = enuMagister_CorrectionType.Magician;

    my finite-state-machine's multiple options are cancelled when I tell my Magister to do nothing but 'magician' routine.  When I make this change (adding the last line above) to force a specific outcome, C#2019 stops responding for a minute or more ... so I think what its doing is 'optimizing' the code during run-time and taking its good-ole time about it.  If that is what is happening, how can i disable this 'optimization'?  and if that is not what is happening, how can I make these debugging changes and not have to wait a painful 90 seconds wondering why its not keeping up with me?

    BadButBit


    my code is perfect until i don't find a bug


    Wednesday, April 3, 2019 10:19 PM

Answers

  • The debugger doesn't "optimize" code at runtime. If you're literally adding that last line to your code then you're using Edit and Continue. If you have that enabled then the debugger has to pause your app, recompile the impacted code and then swap the old page out with the new one. Depending on the change this may or may not work. You can read more about EnC here.

    But this is the wrong way to go about debugging. You don't want to be modifying the actual code while you're debugging. EnC is really for changes that you want to test that would normally require a large amount of reset time. To adjust the value of a variable in your code use the Immediate, Locals, Autos or Watch window to set the new value. The Immediate window in particular allows you to run arbitrary code. None of this requires the debugger to trigger EnC.


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, April 4, 2019 2:15 PM
    Moderator

All replies

  • Hi BadButBit,

    Thank you for posting here.

    According to your code, I could not make sure what cause the error.

    Do you use the magician? If yes, you could post in the link below.

    https://forum.dobot.cc/c/Show-your-ideas

    Best Regards,

    Wendy

    Note: This response contains a reference to a third-party World Wide Web site. Microsoft is providing this information as a convenience to you. 
    Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet. 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 4, 2019 8:38 AM
  • The debugger doesn't "optimize" code at runtime. If you're literally adding that last line to your code then you're using Edit and Continue. If you have that enabled then the debugger has to pause your app, recompile the impacted code and then swap the old page out with the new one. Depending on the change this may or may not work. You can read more about EnC here.

    But this is the wrong way to go about debugging. You don't want to be modifying the actual code while you're debugging. EnC is really for changes that you want to test that would normally require a large amount of reset time. To adjust the value of a variable in your code use the Immediate, Locals, Autos or Watch window to set the new value. The Immediate window in particular allows you to run arbitrary code. None of this requires the debugger to trigger EnC.


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, April 4, 2019 2:15 PM
    Moderator
  • thank you for your reply, 

    but the 'magician' in my code refers to a magician animation my Magister character does to help the user solve a puzzle.

    BadButBit


    my code is perfect until i don't find a bug

    Friday, April 5, 2019 1:45 PM