![]() dnSpy will decompile everything, including the. Go to Debug | Call Stack window and navigate to the topmost method in your own assembly.Go to Debug | Threads window (Ctrl+Alt+h) and click on the main thread.Click Debug | Attach to process (Ctrl+Alt+P).Make sure you open the same bitness executable (x86, 圆4) as the debugged application. Using dnSpy is pretty much like using Visual Studio: Here’s me debugging my deadlock with dnSpy, after taking care to delete the symbols and source code: This means that you can attach to your hanged process, hit Break (Ctrl + Break) and see the line of code where the process is stuck on any machine, including a production machine. It decompiles the code, shows it and even enables setting breakpoints inside the decompiled code. NET application without having the symbols or the original source code. Attach to the frozen process with dnSpyīefore, it’s actually an amazing tool. I really should be doing better error handling. HttpClient httpClient = new HttpClient() In this case, it shows my application keeps trying to do a GET call with no success and **endless retries**. ![]() Here’s me debugging a frozen application: As you can see, the UI thread spends 100% of the recorded time in the method `PrintCustomers`. Open the UI Thread only and investigate.This will open a “Performance Viewer” window After a few seconds of recording, click “Get Snapshot and Wait”.Choose your application by name or with the Drag & Drop tool.Profiler like me, then follow these steps: This is very useful when the hang is caused by some kind of infinite loop, or an infinite retry mechanism. With a performance profiler, instead of breaking in a specific point, you will be able to record the execution for some time and see which methods are being called during the freeze. Attach to the hung process with a performance profilerĪttaching to a performance profiler is a little different than attaching with Visual Studio. Now that we see the problem, it’s easy to fix in a number of ways So our program is hung because the worker thread is waiting on the UI thread, but the UI thread is never released because it’s waiting for the worker thread to finish. Looking at the other threads will reveal that a worker thread (thread-pool thread) is waiting on Dispatcher.Invoke. The image shows the main thread (UI thread) stuck on. Private void ButtonBase_OnClick( object sender, RoutedEventArgs e)Īnd here’s what I see when attaching to the process in Visual Studio: Here’s a piece of my code that causes a deadlock If your application is stuck, that means the UI thread is stuck. In a desktop application, the most important thing to investigate is the UI thread. In most cases, that’s enough to find the deadlock. If not, you will still be able to see the Call Stack, Threads, and Locals windows. If you’re on a development machine with symbol files (.pdb files) included and you have the same version of the source code as the running program, you will be able to see the source code. Hit Debug | Break All (Ctrl+Alt+Break) to stop the runtime and debug the problem.Choose your process from the list and click Attach.In the menu choose Debug | Attach to Process (Ctrl+Alt+P).Uncheck “Enable Just My Code” in Tools | Options | Debugging (this might not be necessary on a development machine).Open a Visual Studio instance (no need to open a solution or project).If you’re not running from Visual Studio, but VS is installed on the machine, you can attach to the hanged process and debug it in the same matter. Then, explore the Call Stack of the main thread to find out why the UI is stuck. When you run your app from Visual Studio directly, you can hit Debug | Break All when the application freezes. Attach to the frozen process with Visual Studio In a web application you might have hung requests on the server, which we’ll talk about as well. An application freeze is more relevant to desktop application where there’s a UI thread present that freezes user interaction. We’re going to explore tools and debugging techniques to see where the program is stuck and to find the core cause of the issue. Instead, this article is about what we are to do when our. We’re not going to talk why there’s just one thread for UI (though that’s an interesting topic). There’s just one thread that can make UI changes, respond to events, and so on. There’s a core issue that causes this problem, and that is a single UI thread. How many times did you use a desktop application to end up with a frozen unresponsive window? Don’t know about you, but it happened to me more times than I can count. NET application Freezes (hangs) Debugging
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |