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 8525577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:01:17+00:00 2026-06-11T08:01:17+00:00

The case is that in my project i have a bottom control to start

  • 0

The case is that in my project i have a bottom control to start and check the Windows service and write the status of the Windows service in a textBlock control. But, the problem is it displays the “Windows service is running”, then “Windows service is stopped”, and then “Windows service is running” again.

This goes like “A” to “B” and then “A” again.

I want this to flow from “B” to “A” without having the “A” at the beginning.

private void btnStart_Click(object sender, RoutedEventArgs e)
{
    if (ValidationHelpers.IsValid())
        StartService();
    else
        _serviceControll.StopService();
}

  private void StartService()
        {
            try
            {
                if (!_serviceIsStarted)
                {
                    if (_serviceControll.StartService())
                    {

                        var startThread = new Thread(new ThreadStart(CheckStartService));
                        startThread.Start();

                        statusTextBlock.Text = "Offline IM service is running";
                        statusTextBlock.Foreground = Brushes.Black;
                    }
                    else
                    {
                        statusTextBlock.Text = "Offline IM service is stopped";
                        statusTextBlock.Foreground = Brushes.Red;
                    }
                }
            }
            catch (Exception exception)
            {

                statusTextBlock.Text = "Error in starting the Offline IM service " + exception.Message.ToString();
                statusTextBlock.Foreground = Brushes.Red;
            }
        }



    private void CheckServiceStatus()
    {
        try
        {
            if (_serviceControll.CheckServiceStatus())
            {
                statusTextBlock.Text = "Offline IM service is running";
                statusTextBlock.Foreground = Brushes.Black;
                _serviceIsStarted = true;
            }
            else
            {
                statusTextBlock.Text = "Offline IM service is stopped";
                statusTextBlock.Foreground = Brushes.Black;
                _serviceIsStarted = false;
            }
        }
        catch (Exception exception)
        {
            statusTextBlock.Text = "Error in getting the Offline IM service status " + exception.Message.ToString();
            statusTextBlock.Foreground = Brushes.Red;
        }
    }


  private void CheckStartService()
        {
            var set = true;
            while (set)
            {
                if (_serviceControll.CheckServiceStatus())
                {
                    MessageBox.Show(@"Offline IM service is started", "Offline IM Configuration Manager",
                                          MessageBoxButton.OK, MessageBoxImage.Information);
                    _serviceIsStarted = true;
                    set = false;
                }
            }
            return;
        }


    private void DispatcherTimerTick(object sender, EventArgs e)
    {
        if (_serviceControll != null)
        {
            CheckServiceStatus();
        }

    }

}
  • 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-06-11T08:01:19+00:00Added an answer on June 11, 2026 at 8:01 am

    One this is not good.

       startThread.Start();
    
       statusTextBlock.Text = "Offline IM service is running";
       statusTextBlock.Foreground = Brushes.Black;
    

    Just because you start the thread does not mean the the service is running.

    This I am not following at all

    if (_serviceControll.CheckServiceStatus())
    

    CheckServiceStatus() that you have posted returns a void

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My use case is this... I have a project that has two production branches.
In a base clear case project that I have, the config spec handed to
EDIT: Fixed most of the problem (but not too sure why). Check the bottom
We have a business case that would be perfect for multiple BackgroundWorkers. As an
I currently have a select-case that will read a name field from a recordset,
I have a very specific case that I need to debug. I need to
How do i get access to a control (linkbutton in my case) that is
I have an extremely odd problem in my JUnit tests that I just can't
I have a MVC 3 project that uses Entity Framework. I can successfully update
I currently have a pre-commit hook in my mercurial project that gives the user

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.