Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 830779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:06:03+00:00 2026-05-15T04:06:03+00:00

I have a Windows service that I’d like to gather some debugging data on

  • 0

I have a Windows service that I’d like to gather some debugging data on using Intellitrace – the problem is that you can’t debug a Windows Service by starting it directly from inside VS. I have the service installed, and the very first statement in Service.Start is “Debug.Break”, which allows me to attach VS. However, you can’t use Intellitrace if a process is already started when you attach.

Does anybody know of a workaround for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:06:03+00:00Added an answer on May 15, 2026 at 4:06 am

    It is possible with a little bit of work. The general idea is to mock up a console application that will call the OnStart and OnStop methods of the service. It’s not the exact start and stop path a service will go through but hopefully it get you to the point that you can diagnose your issue. I included some sample code to give you a general idea.

    ConsoleMock.cs:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using WindowsService1;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Service1 s1 = new Service1();
                while (true)
                {
                    Console.WriteLine(">1 Start\n>2 Stop");
                    string result = Console.ReadLine();
                    if (result == "1")
                    {
                        var method = s1.GetType().GetMethod("OnStart", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                        method.Invoke(s1, new object[] { args });
                    }
                    else if (result == "2")
                    {
                        var method = s1.GetType().GetMethod("OnStop", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                        method.Invoke(s1, new object[] { });
                    }
                    else
                    {
                        Console.WriteLine("wrong command");
                    }
                }
            }
        }
    }
    
    
    Service.cs:
        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.Data;
        using System.Diagnostics;
        using System.Linq;
        using System.ServiceProcess;
        using System.Text;
        using System.Threading;
    
        namespace WindowsService1
        {
            public partial class Service1 : ServiceBase
            {
                private long serviceCounter;
                private Thread workerThread;
    
                public Service1()
                {
                    InitializeComponent();
                    serviceCounter = 0;
    
                }
    
                public void Worker()
                {
                    while (true)
                    {
                        serviceCounter += 1;
                        System.Threading.Thread.Sleep(500);
    
                        try
                        {
                            throw new Exception(serviceCounter.ToString());
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
    
                protected override void OnStart(string[] args)
                {
                    workerThread = new Thread(new ThreadStart(Worker));
                    workerThread.Start();
                }
    
                protected override void OnStop()
                {
                    workerThread.Abort();
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.