Locating an EventHandler through Application Usage C# - c#

I'm converting a program from visual basic to C#, and in order to test it I need to change the configs so that when a menu option from a menu that appears after a right-click is pressed it calls the C# code I created rather than the old Visual Basic code. Obviously, that means locating the event handler. Unfortunately, I don't know the name of the menu option being pressed and have yet to guess what it is. Is there a way for me to run the application, and have the program pause (like a breakpoint) at the very first thing it does after the menu-option is pressed in the application? Right now I have a breakpoint on the first line of the method that is run. But is there a way to find the eventHandler that triggers that method, by running the program? Or is there another option to help me find what's triggering it?

Related

Is there a single event which gets triggered before a project is started?

I'm writing an extension which needs to set command line arguments on a project before it is started in visual studio.
Currently, I try to handle the different events which lead to a project start.
However, some cases are hard to get right, e.g. pressing F10/F11.
Is there a single event which gets explicitly triggered before a project is started?
Preferably an IVS* interface API.
Note that there are several ways to start a project in visual studio with or without a debugger, thus reacting to Start/StartNoDebug commands are not a feasible solution.

Visual Studio Extension subscribe to a debugger event

I'm developing a visual studio extension and now I'm facing a problem:
How do I subscribe to a Brake Point, i.e. every time the debugger catches the Brake Point, I would like to perform some action.
I can split this single problem into 2 problems:
1. How do I fire a function without pressing anything (I understand that the event should do this)
2. What function should I call to see the breakpoints (make my function fire)
(Don't see any reason to put any code because this is a HOWTO question and for real I don't have what to show)
Thanks for any help!!
You can use DTE.Events.DebuggerEvents and DTE.Debugger to receive notifications of a break point and get information about it.

getting the debugger to break at the next click event

in a .net windows forms project which has 100s of forms, and all those forms has countless custom made controls with base classes involved, its very difficult for me to know where a particular button is, i mean whats the form name which I'm looking at while i'm running the application, and where exactly is the button click event, in code, of the button that I just clicked. Is there a debugging feature in Visual Studio, which would just break the execution for me to the line where the click happened. Can I tell VS to break at which ever Click event comes next?
(running visual studio 2012/13 these days).
thanks.
Just before you click the button in the program do this:
Go to visual studio and pause the program. Just press the pause button.
Then press F11 (Step Into).
Now press the button in the program, and you should be taken into the event handler.
For web projects, the technique suggested by Jakob Olsen will not really work, because you have no active thread in between the calls, and hence no thread to resume upon the next action. However what worked for me was:
Find some code (any code in your app) you know for sure it gets executed and set a breakpoint
Trigger this breakpoint, use SHIFT-F11 to step out until you're out of all methods
Now do the action of which you don't know what code is executed, and it will break
I can suggest partial solution.
If your click events are named like "Button_Click", open Breakpoints windows while in debug and create New breakpoint.
Click OK and you will see list of functions. Check them and click OK. On every function that you have selected will be created a breakpoint.

In Visual Studio 2012/2013 is it possible to have breakpoints or methods listed automatically while debugging

I did some research on this before asking the question and since I might be asking it incorrectly, I might not have done the right searches here first.
What I am trying to accomplish is when I start to debug or run an application in Visual Studio, is to have the IDE show me what methods are executing when I do something in the GUI/application.
For instance if I click a button in the GUI labelled "Search", I want to see the chain of events/methods that execute for this process. This I am not sure of. I hope I have asked the question correctly. Thank you for your time.
Have a try with IntelliTrace.
Make sure IntelliTrace is enabled and call information is selected;
Launch your GUI application, and perform what action you want;
In IntelliTrace window, click Break All. If IntelliTrace window is not displayed, click Debug -> Windows -> IntelliTrace Event;
Expand the event you are interested, for example, 'Clicked Search', and click Call View link;
You can see call stack you are interested.
There are two ways to approach this:
If you have no idea where the code you are looking for is, then simply start your program with a Profiler such as JetBrains dotTrace. Then, get ready to push the button, click "Start Profiling", click the button, and then as soon as the operation is finished, click "Get Snapshot". Now, use dotTrace's Call Tree to see which methods called which. I use this technique all the time for just this purpose!
In this view, you can use the arrows key to navigate the method-calls tree.
If you have a general idea of which class[/es] get invoked when you hit the button on the GUI, but don't know exactly which methods are called, you can use OzCode's "Add Breakpoint to Every Method" on a class, so that even if you don't know the exact method that's about to be called, whenever the class is accessed, you'll break into the debugger and be able to explore.
Due Diligence Disclaimer: I am a co-creator of OzCode.
You can use the Runtime Flow tool (commercial, developed by me) to see the chain of events/methods in a .NET application for GUI actions.

Check icon in menu

I have been developing a windows application. I had built a menu bar. When I click on the menu option once, it show a checked sign. But again when I click on the same option the check sign does not goes off.
The code I had written is:
nmviewtextbox.Checked = !nmviewtextbox.Checked;
but its showing an error
I understand that you are calling this code from the CheckedChanged event and thus you are provoking an endless loop (this event is called every time nmviewtextbox.Checked is changed). In that case, delete this line (the method would continue working without any problem).
Otherwise (outside the event triggered when .Checked is changed), this code should work fine.
Bear in mind that, as suggested by Cody Gray, you can disable the check-on-click functionality (and thus allow this line of code to work without triggering any error).

Categories