{"id":1193,"date":"2015-02-02T09:00:03","date_gmt":"2015-02-02T17:00:03","guid":{"rendered":"http:\/\/www.coretechnologies.com\/blog\/?p=1193"},"modified":"2025-12-28T23:37:47","modified_gmt":"2025-12-29T07:37:47","slug":"how-to-debug-windows-services","status":"publish","type":"post","link":"https:\/\/www.coretechnologies.com\/blog\/windows-services\/how-to-debug-windows-services\/","title":{"rendered":"Investigate Crashes &#038; Memory Leaks in your Windows Services with Microsoft&#8217;s Debug Diagnostic Tool"},"content":{"rendered":"<div align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" src=\"\/blog\/images\/debugdiag-logo.jpg\" width=\"383\" height=\"146\" border=\"0\" title=\"Microsoft Debug Diagnostic Tool\" alt=\"Microsoft Debug Diagnostic Tool\" \/><\/div>\n<p>\nCrashes and memory leaks are particularly offensive when the occur in windows services &#8211; applications designed to run unattended, 24\/7 in the background to perform important tasks. Our <a href=\"\/products\/AlwaysUp\/\" target=\"_blank\" rel=\"noopener noreferrer\">AlwaysUp<\/a> and <a href=\"\/products\/ServiceProtector\/\" target=\"_blank\" rel=\"noopener noreferrer\">Service Protector<\/a> utilities go a long way to diminishing the effect of these insidious failures, but using them is no substitute for finding and fixing a problem at its root.\n<\/p>\n<p>\nDevelopers looking to diagnose failures in their windows services should consider using <a href=\"https:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=58210\" target=\"_blank\" rel=\"noopener noreferrer\">Microsoft&#8217;s Debug Diagnostic Tool<\/a>. This free desktop application, nicknamed DebugDiag, will monitor your windows service process and create a &#8220;dump&#8221; describing the state of the application when it crashed (or started using too much memory). You can use this information to narrow down the problem in your own code, or pass it on to the folks who developed the failing service for their expert analysis.\n<\/p>\n<hr class=\"blog-section\">\n<div style=\"width:100%;margin-bottom:30px;\">\n<div style=\"margin:0px;float:right;\"><a href=\"#top\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cdn.coretechnologies.com\/images\/top.jpg\" border=\"0\" width=\"50\" height=\"18\" title=\"Go to the top\" alt=\"\" \/><\/a><\/div>\n<\/div>\n<h2 class=\"blog-caption\">Using the Debug Diagnostic Tool on your Windows Service<\/h2>\n<ol>\n<li>\n<p>\n<a href=\"https:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=58210\" target=\"_blank\" rel=\"noopener noreferrer\">Download<\/a> the Debug Diagnostic Tool from microsoft.com.\n<\/p>\n<\/li>\n<li>\n<p>\nInstall it. Setup should be quite straightforward, with the usual prompts for a folder, etc.\n<\/p>\n<\/li>\n<li>\n<p>\nFrom Windows Explorer, navigate to the folder where DebugDiag was installed (C:\\Program Files\\DebugDiag<\/b> by default). Start <b>DebugDiag.Collection.exe<\/b> &#8211; the application that monitors and collects information from a running process or service.\n<\/p>\n<p>\n<a href=\"\/blog\/images\/start-debugdiag-collection-application.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Start DebugDiag.Collection.exe\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/start-debugdiag-collection-application.png\" border=\"0\" title=\"Start DebugDiag.Collection.exe (click to enlarge)\" alt=\"Start DebugDiag.Collection.exe\" width=\"540\" \/><br \/>\n<\/a>\n<\/p>\n<\/li>\n<li>\n<p>\nThe Debug Diagnostic Tool window should come up and you will be launched immediately into setting up a new &#8220;rule&#8221; describing what to watch for. From here, you can specify to monitor for crashes, leaks, and even performance-related issues. We&#8217;ll select <b>Crash<\/b> for this tutorial and click Next to move on.\n<\/p>\n<p>\n<a href=\"\/blog\/images\/debugdiag-select-rule-type.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"DebugDiag: Select Crash Option\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/debugdiag-select-rule-type.png\" border=\"0\" title=\"DebugDiag: Select Crash Option (click to enlarge)\" alt=\"DebugDiag: Select Crash Option\" width=\"540\" \/><br \/>\n<\/a>\n<\/p>\n<\/li>\n<li>\n<p>\nNext, select the <b>A Specific NT service<\/b> option:\n<\/p>\n<p>\n<a href=\"\/blog\/images\/debugdiag-select-windows-service-option.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"DebugDiag: Select Windows Service Option\" target=\"_blank\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/images\/debugdiag-select-windows-service-option.png\" width=\"457\" height=\"402\" border=\"0\" title=\"DebugDiag: Select Windows Service Option (click to enlarge)\" alt=\"DebugDiag: Select Windows Service Option\" \/><br \/>\n<\/a>\n<\/p>\n<\/li>\n<li>\n<p>\nSelect the service you wish to debug from the list. We chose &#8220;AA MyService&#8221;, a windows service we developed to test our Service Protector application. Click Next.\n<\/p>\n<p>\n<a href=\"\/blog\/images\/debugdiag-select-windows-service-name.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"DebugDiag: Select Windows Service\" target=\"_blank\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/images\/debugdiag-select-windows-service-name.png\" width=\"457\" height=\"402\" border=\"0\" title=\"DebugDiag: Select Windows Service (click to enlarge)\" alt=\"DebugDiag: Select Windows Service\" \/><br \/>\n<\/a>\n<\/p>\n<\/li>\n<li>\n<p>\nAlmost there! Leave the <b>Advanced Configuration<\/b> settings at their default values and click Next to continue:\n<\/p>\n<p>\n<a href=\"\/blog\/images\/debugdiag-advanced-configuration.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"DebugDiag: Windows Service Advanced Configuration\" target=\"_blank\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/images\/debugdiag-advanced-configuration.png\" width=\"457\" height=\"402\" border=\"0\" title=\"DebugDiag: Windows Service Advanced Configuration (click to enlarge)\" alt=\"DebugDiag: Windows Service Advanced Configuration\" \/><br \/>\n<\/a>\n<\/p>\n<\/li>\n<li>\n<p>\nYou don&#8217;t have to make any changes on the <b>Select Dump Location<\/b> screen either &#8211; just make a note of where the dump file will be saved.\n<\/p>\n<p>\n<a href=\"\/blog\/images\/debugdiag-dump-location.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"DebugDiag: Windows Service Dump Location\" target=\"_blank\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/images\/debugdiag-dump-location.png\" width=\"457\" height=\"402\" border=\"0\" title=\"DebugDiag: Windows Service Dump Location (click to enlarge)\" alt=\"DebugDiag: Windows Service Dump Location\" \/><br \/>\n<\/a>\n<\/p>\n<\/li>\n<li>\n<p>\nAnd finally, let&#8217;s activate the rule now and click Finish:\n<\/p>\n<p>\n<a href=\"\/blog\/images\/debugdiag-activate-now.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"DebugDiag: Activate Now\" target=\"_blank\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/images\/debugdiag-activate-now.png\" width=\"457\" height=\"402\" border=\"0\" title=\"DebugDiag: Activate Now (click to enlarge)\" alt=\"DebugDiag: Activate Now\" \/><br \/>\n<\/a>\n<\/p>\n<p>\nAfter a few seconds, the tool will be monitoring your windows service for crashes:\n<\/p>\n<p>\n<a href=\"\/blog\/images\/debugdiag-rule-created.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"DebugDiag: Windows Service Rule Created\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/debugdiag-rule-created.png\" border=\"0\" title=\"DebugDiag: Windows Service Rule Created (click to enlarge)\" alt=\"DebugDiag: Windows Service Rule Created\" width=\"540\" \/><br \/>\n<\/a>\n<\/p>\n<\/li>\n<\/ol>\n<hr class=\"blog-section\">\n<div style=\"width:100%;margin-bottom:30px;\">\n<div style=\"margin:0px;float:right;\"><a href=\"#top\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cdn.coretechnologies.com\/images\/top.jpg\" border=\"0\" width=\"50\" height=\"18\" title=\"Go to the top\" alt=\"\" \/><\/a><\/div>\n<\/div>\n<h2 class=\"blog-caption\">Analyzing a Windows Service Crash<\/h2>\n<p>\nWhen the service crashes, DebugDiag will record a dump file and increment the <b>Userdump count<\/b> column. Here we can see that 1 crash has occurred and been captured (with the full path to the dump file noted on the right):\n<\/p>\n<p>\n<a href=\"\/blog\/images\/debug-diag-service-crashed.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"DebugDiag: Windows Service Crashed\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/debug-diag-service-crashed.png\" border=\"0\" title=DebugDiag: Windows Service Crashed (click to enlarge)\" alt=\"DebugDiag: Windows Service Crashed\" width=\"540\" \/><br \/>\n<\/a>\n<\/p>\n<p>To dig into the dump file:<\/p>\n<ol>\n<li>\n<p>\nStart <b>DebugDiag.Analysis.exe<\/b> from Windows Explorer:\n<\/p>\n<p>\n<a href=\"\/blog\/images\/start-debugdiag-analysis.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Start DebugDiag.Analysis.exe\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/start-debugdiag-analysis.png\" border=\"0\" title=\"Start DebugDiag.Analysis.exe (click to enlarge)\" alt=\"Start DebugDiag.Analysis.exe\" width=\"540\" \/><br \/>\n<\/a>\n<\/p>\n<p>\nThe <b>DebugDiag Analysis<\/b> window will open momentarily:\n<\/p>\n<p>\n<a href=\"\/blog\/images\/debugdiag-analysis-started.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"DebugDiag Analysis Started\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/debugdiag-analysis-started.png\" border=\"0\" title=\"DebugDiag Analysis Started (click to enlarge)\" alt=\"DebugDiag Analysis Started\" width=\"540\" \/><br \/>\n<\/a>\n<\/p>\n<\/li>\n<li>\n<p>\nTo configure analysis:\n<\/p>\n<ol type=\"a\">\n<li>Check the <b>CrashHangAnalysis<\/b> box near to the top.<\/li>\n<li>Click the <b>Add Data Files<\/b> button, navigate to the location of the dump file (it is mentioned in the Diagnostic tool we set up previously) and select it. A new entry should show up in the lower pane.<\/li>\n<\/ol>\n<p>\n<a href=\"\/blog\/images\/debugdiag-analysis-configure.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Configure Analysis\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/debugdiag-analysis-configure.png\" border=\"0\" title=\"Configure Analysis (click to enlarge)\" alt=\"Configure Analysis\" width=\"540\" \/><br \/>\n<\/a>\n<\/p>\n<\/li>\n<li>\n<p>\nAnd click the <b>Start Analysis<\/b> button to get going! After a period of &#8220;thinking&#8221;, the application will open its report in your browser:\n<\/p>\n<p>\n<a href=\"\/blog\/images\/debugdiag-analysis-report.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Analysis Summary Report\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/debugdiag-analysis-report.png\" border=\"0\" title=\"Analysis Summary Report (click to enlarge)\" alt=\"Analysis Summary Report\" width=\"540\" \/><br \/>\n<\/a>\n<\/p>\n<\/li>\n<li>\n<p>\nScan the report for any smoking guns. Thread call stacks may be particularly useful. For example, this stack trace tells us that our service crashed while handling a button press. (This is not surprising though &#8211; that is what we did to force the crash in our testing!)\n<\/p>\n<p>\n<a href=\"\/blog\/images\/debugdiag-analysis-crash-call-stack.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Windows Service Call Stack\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/debugdiag-analysis-crash-call-stack.png\" border=\"0\" title=\"Windows Service Call Stack (click to enlarge)\" alt=\"Windows Service Call Stack\" width=\"540\" \/><br \/>\n<\/a>\n<\/p>\n<p>\nHopefully you will find a telltale sign to help you identify and fix your problem.\n<\/p>\n<\/li>\n<\/ol>\n<hr class=\"blog-section\">\n<div style=\"width:100%;margin-bottom:30px;\">\n<div style=\"margin:0px;float:right;\"><a href=\"#top\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cdn.coretechnologies.com\/images\/top.jpg\" border=\"0\" width=\"50\" height=\"18\" title=\"Go to the top\" alt=\"\" \/><\/a><\/div>\n<\/div>\n<h2 class=\"blog-caption\">Also Find Memory Leaks in your Windows Service<\/h2>\n<p>If your windows service is consuming too much memory instead of crashing, configure the collector to watch for memory leaks:<\/p>\n<p>\n<a href=\"\/blog\/images\/debugdiag-find-memory-leaks.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Find Windows Service Memory Leaks\" target=\"_blank\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/images\/debugdiag-find-memory-leaks.png\" width=\"457\" height=\"402\" border=\"0\" title=\"Find Windows Service Memory Leaks (click to enlarge)\" alt=\"Find Windows Service Memory Leaks\" \/><br \/>\n<\/a>\n<\/p>\n<p>The final report will detail all outstanding memory allocations.<\/p>\n<p>&nbsp;<\/p>\n<p>Good hunting!<\/p>\n<div style=\"margin-top:30px\" align=\"center\">\n<div class=\"cta-button-1\">\n<table role=\"presentation\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" align=\"left\">\n<tbody>\n<tr>\n<td align=\"center\"><a href=\"\/blog\/tag\/windows-services-2\/\" title=\"More articles about Windows Services\"><span><nobr>More articles about Windows Services&#8230;<\/nobr><\/span><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<!-- relpost-thumb-wrapper --><div class=\"relpost-thumb-wrapper\"><!-- filter-class --><div class=\"relpost-thumb-container\"><style>.relpost-block-single-image, .relpost-post-image { margin-bottom: 10px; }<\/style><h3>You may also like...<\/h3><div style=\"clear: both\"><\/div><div style=\"clear: both\"><\/div><!-- relpost-block-container --><div class=\"relpost-block-container relpost-block-column-layout\" style=\"--relposth-columns: 3;--relposth-columns_t: 2; --relposth-columns_m: 2\"><a href=\"https:\/\/www.coretechnologies.com\/blog\/windows-services\/spooler\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Essential Windows Services: Spooler\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/computers-printing-150x150.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Essential Windows Services: Spooler<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/top-5-reasons-to-run-your-application-as-a-windows-service\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"The Top 5 Reasons to Run Your Application as a Windows Service\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/top-5-150x150.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">The Top 5 Reasons to Run Your Application as a Windows Service with AlwaysUp<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/srvany\/top-3-srvany-problems\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"The Top 3 Real-World Problems with Microsoft Srvany\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/service-caution-150x150-1.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">The Top 3 Real-World Problems with Microsoft Srvany<\/h2><\/div><\/div><\/a><\/div><!-- close relpost-block-container --><div style=\"clear: both\"><\/div><\/div><!-- close filter class --><\/div><!-- close relpost-thumb-wrapper -->","protected":false},"excerpt":{"rendered":"<p>Crashes and memory leaks are particularly offensive when the occur in windows services &#8211; applications designed to run unattended, 24\/7 in the background to perform important tasks. Our AlwaysUp and Service Protector utilities go a long way to diminishing the &hellip; <a href=\"https:\/\/www.coretechnologies.com\/blog\/windows-services\/how-to-debug-windows-services\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":2265,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[398,66,196],"class_list":["post-1193","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-windows-services","tag-debugdiag","tag-debugging","tag-windows-services-2"],"_links":{"self":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/1193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=1193"}],"version-history":[{"count":4,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/1193\/revisions"}],"predecessor-version":[{"id":13301,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/1193\/revisions\/13301"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media\/2265"}],"wp:attachment":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=1193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=1193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=1193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}