Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Multithreaded windows service

Multithreaded windows service

Scheduled Pinned Locked Moved C#
databasehelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vijay Kulavade
    wrote on last edited by
    #1

    Hi experts, I wanted to create a multi threaded windows service, can anyone reply me with the code, i will appreciate it. The scenario is, i have multiple databases, and i have to connect to each database and do some work after each interval using windows service. I could not able to find a simple multi threaded windows service code sample anywhere :confused: Help needed, thanks, Vijay Vijay

    G 1 Reply Last reply
    0
    • V Vijay Kulavade

      Hi experts, I wanted to create a multi threaded windows service, can anyone reply me with the code, i will appreciate it. The scenario is, i have multiple databases, and i have to connect to each database and do some work after each interval using windows service. I could not able to find a simple multi threaded windows service code sample anywhere :confused: Help needed, thanks, Vijay Vijay

      G Offline
      G Offline
      Guinness4Strength
      wrote on last edited by
      #2

      I would be surprised if anyone would be able to post code for this type of request. I have written a few multithreaded services and can give you some pointers. 1. I usually put all of the code used by the thread in its own DLL, that way you can basically insantiate an instance of you class for each thread and limit the race conditions which can occur between threads. 2. Create a single public method in your class which can be the starting point for your thread, populate class properties with initial values in the Service code then use the ThreadStart or ParameterizedThreadStart methods to start the thread. Once the Thread has started (you can use ManualResetEvents to monitor this) add the Thread instance to an array in the Service code so all of the running threads canbe managed from the service. Doing so will allow you to stop the threads in the event that the service must stop. 3. I've found that .NET remoting is especiall handy with M-threaded Windows Services for sending control / command requests to the threads. Here is an example of starting a thread:

      try
      {
      m_ThreadStarted.Reset();
      //ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessADTThread), DR);
      Thread ADTThread = new Thread(new ParameterizedThreadStart(ProcessADTThread));
      ADTThread.IsBackground = true;
      m_MasterThreadList.Add(ADTThread);
      ADTThread.Start(DR);
      m_ThreadStarted.WaitOne(-1, false);
      Lines.Append(DR["ClientName"].ToString() + " Started\r\n");
      }
      catch (Exception Err)
      {
      m_ServiceLog.WriteEntry("Start Service WaitEvent Exception: " + Err.Message, EventLogEntryType.Error);
      }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups