Visual Studio Profiling: Start/Stop from code - c#

Is there a possibility to start/stop the visual studio (Professional 2012+) profiler from code? I know you can start it paused, but to start the profiling, you have to click on a button in the visual studio.
In my case, I would like to start it when clicking on a button in my application, which switches to a new view, and automatically stop it when the UI was loaded. I would like to see why there is such a large delay until the UI shows up.

I've not used it before, but it seems you're looking for Profiling API.
DataCollection.StartProfile and DataCollection.StopProfile looks like the methods you're interested in.

Related

Breaking on code triggered by target application UI event in Visual Studio

I've been debugging a WPF application bequeathed to me by a gentleman who is fond of making interesting architectural decisions. As a result, I'm having trouble locating the code that runs when a user clicks an on-screen menu item. Following the binding from the view to the viewmodel got me to some collection of "control functions" that's initialized at startup (apparently, all manner of different controls with varying functions had to go into a single collection). I've managed to find some code that's triggered by the click, but it's too deep, too far removed from the click event to be of any use to me.
This got me thinking...
In Visual Studio, (I'm using VS2015) when the application isn't running, if you select Debug -> Step into, debug is triggered, and then the debugger breaks on the very first line of the code (in my case the constructor call of the class that inherits from System.Windows.Application)
Isn't there a way to do this while the application is already running? Let's say I've started a WPF (or WinForms) application, a window has been displayed, the UI thread is running and awaiting user input. The user clicks on a button, and some code is executed. But unless there's a breakpoint in the code, the debugger doesn't do anything about it. As I've explained, this can be a problem if I don't know which code is actually run. Is there a way to tell Visual Studio, "listen, if the user clicks on something, break on the first line of (user) code triggered by this action." Is that possible?

React on Visual Studio Stop

Is there the possibility to run some code when the Code is stopped when running it from Visual Studio?
I am using the CefGlue library to build a WinForms application and realized that there are issues when pressing the stop button ranging from Exception to two windows with no content opening. A separate process continues to run in the background. In order to stop Cef nicely I need to exectue CefRuntime.Shutdown(); Maybe this is because it does not run the application in a Visual Studio hosting process, because CefGlue has problem with this (see this). This does not affect production but is nasty while developing and testing, but nevertheless I would like to execute some code to fix the problem.
I would guess this is not possible but if it was it would be interesting to know.
So I am looking for a way to execute some code when Visual Studio is stopping the application when pressing the stop button while in development.
Note: I am using Visual Studio 2013 and 2015.
Edit
The issue is not reproducibly with very few lines of code. Nevertheless I have tried to create a simplified example here
What you're basicly looking for is a solution using the Visual Studio SDK.
You can build your own add-ins by implementing the IDTExtensibility interface.
In the OnConnection function you can subscribe to different events. Using (DTE2)application you can access a lot of things from VS.
You'll have to subscribe to some of the events that can be obtained from the Events property.
You'll have to find out yourself what events work best for your solution. But the DebuggerEvents would seem like a good place to start.
This does require some research before you can use it. There are likely to be easier solutions.
As a simple example for the OnConnection:
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
var applicationObject = (DTE2)application;
var events = _applicationObject.Events;
var buildEvents = (BuildEvents)events.BuildEvents;
buildEvents.OnBuildBegin += new _dispBuildEvents_OnBuildBeginEventHandler(OnBuildBegin);
}
This triggers when a build is started. The available documentation isn't great, so it will need some trial-and-error before you find what you need.

How do I Force suspension of Metro app

How do we force an app to Suspend (NOT shutdown, just suspend) and then force-resume it ourselves when we are NOT using visual studio/debugging?
When running under Visual Studio 2012, you can enable the Debug Location on the debugger toolbar. This will allow you to select one of the three operations, "suspend", "resume", and "suspend and shutdown".
[edited]
Sorry, just noticed that you are asking for non VS solution. You can suspend your app by dragging the app down. Move your cursor to the top of the page until you see a hand. Click and hold it and pull down to suspend your app. It takes a few seconds before the app actually enter suspend mode. If you want to do things sooner, you can use visibility change to toggle certain action first, like saving critical stuff.

Is there a way to see a history of function calls in visual studio?

Working on a project that keeps crashing. No errors and showing up, my memory monitor tells me that everything is normal and as far as I can see there is nothing aberrant in my code it just stops working, freezes. Is there a way to see a history in visual studio of function calls so I can ascertain accurately the last thing my program does before it breaks?
Thanks!
menu bar -> DEbug -> Windows -> Call Stack

WPF Application stalls/freezes after first interaction, like button click

I'm currently experiencing a problem in WPF. The UI loads fine, but whenever the first user interaction is made, such as a button click, the application seems to stall, or example if I had two buttons that display a MessageBox, the first click will wait for a few seconds then show the MessageBox, but any subsequent interaction is instantaneous and responsive.
Has anyone else experienced this? And if so, is there any solution?
Thanks
I had the same problem. Every time I called the first interaction from a Button or ICommand the UI would freeze for like half a second.
I tracked down the issue with the hint of the author to start application directly from the folder. This solved the issue, but I also wanted to know why this happens and thought about what the difference is between direct execution and debugging.
So I figured out that IntelliTrace caused the freeze, which was still enabled since I activated it once for debugging an ADO.NET application. After disabling, the UI Freeze is gone. To disable it go to Debug -> IntelliTrace -> Open IntelliTrace Settings -> untick "Enable IntelliTrace".
Thanks for reporting this performance issue. We have looked into it and tracked it down. We are looking into fixing this in a future release. Below are steps to work around this issue. Once the work around is applied there is no need to disable ‘Gesture’ events or IntelliTrace.
Open up a cmd window under Admin account
cd /d "%programfiles(x86)%\Microsoft Visual Studio 12.0\Common7\IDE\Remote Debugger\x64"
%windir%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe install /NoDependencies /ExeConfig:.\msvsmon.exe Microsoft.VisualStudio.vil.host.dll
If you are using a VM you might want to first save a snapshot before applying the work around. Let us know if you run into any other issues. Thanks.
Azeem Khan

Categories

Resources