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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:41:30+00:00 2026-05-31T07:41:30+00:00

I’ve been reading a lot of tutorials/helpdesks (including this one) on windows services and

  • 0

I’ve been reading a lot of tutorials/helpdesks (including this one) on windows services and threading to figure out the best way to accomplish the below goal. I can’t figure out a few things though, so now i’m wondering if I choose the right way to go or not and if I did, how do I implement it.

The goal:
I need to perform 5 seperate tasks on the background, so I want to create a windows service. Besides the service I want a form application to show information about the service. From what I’ve read I should use a socket server to handle communication.

My plan:

  1. Create a windows service
  2. Create a async socket server class and start it in the onstart method
  3. When the socket server is properly started and ready, call a method
    on the main service startTasks.
  4. Create a seperate class for each task with an executeTask method
  5. In the startTasks method I will start a thread for each task so they
    can all run simultanious.
  6. When a task has something to report it should call a method on the
    main service called sendData(msg)
  7. The senddata method should call a method in the socket server class
    that sends the msg to all connected clients.

The problem is with 3, 6 and 7 and involve the “Call method on other thread/class”.

  • How can I let the asycn server call the startTasks method when its
    ready
  • How can i sendData via this server from a seperate thread.

Simplefied service:

public partial class SecurityCheck : ServiceBase
    {
        private ComServer _comServer;
        private CheckRequest _checkRequest;

        private readonly Thread[] _threads = new Thread[1];
        private int _tNr;

        public SecurityCheck()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            _comServer = new ComServer();
        }

        protected override void OnStop()
        {
            _comServer.CloseSockets();

            if (_checkRequest != null)
                _checkRequest.ServiceStarted = false;

            foreach (Thread t in _threads)
            {
                if (t != null)
                    t.Join(new TimeSpan(0, 2, 0));
            }
        }

        internal void StartTasks()
        {
            _checkRequest = new CheckRequest { ServiceStarted = true };
            var st = new ThreadStart(_checkRequest.ExecuteTask);
            _threads[_tNr] = new Thread(st);
            _threads[_tNr].Start();
            _tNr++;
        }

        internal void SendData(string msg)
        {
            _comServer.SendData(msg);
        }
    }

Simplefied task

public class CheckRequest
{
    public bool ServiceStarted;

    public CheckRequest()
    {
        //construct me
    }

    public void ExecuteTask()
    {
        while (ServiceStarted)
        {
            try
            {
                //perform task

                //what to do to send data?
            }
            catch (Exception ex)
            {

            }

            // yield
            if (ServiceStarted)
            {
                Thread.Sleep(new TimeSpan(0, 0, 10));
            }
        }

        Thread.CurrentThread.Abort();
    }
}
  • 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-31T07:41:33+00:00Added an answer on May 31, 2026 at 7:41 am

    For the communications between the Service and the Clients I would definitely go with (duplex) WCF instead of sockets. This will save you a lot of tedious and errorprone coding.

    Secondly, having a seperate class for each task with a executeTask method sounds like you hail from the Java world or runnable objects. In C#, you can just code the tasks as seperate methods and start them as a task be executed asynchronously. When they have something to report to the clients they can just send it to the clients themselves through a duplex channel between the Clients and the server.

    Using WCF and TPL for this project should pretty much solve all the issues you describe and have you home in time for dinner. It may cost a little time now to get aqcuainted with these newer technologies but it will save you heaps of time lateron by having shorter code that is easier to transfer and has less room for bugs.

    Regards Gert-Jan

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.