RodionP
asked on
Windows service won't run multiple threads
Hi,
I have a little problem:
I am trying to run deploy a windows service (I am using .msi installer to take care of widnows service deployment) and my service is supposed to start many threads
(number of threads depends on the configuration). The problem is when I try to start my service it won't start, and threads won't start. When I try to run this app as windows app, threads start without a problem.
Thank you
I have a little problem:
I am trying to run deploy a windows service (I am using .msi installer to take care of widnows service deployment) and my service is supposed to start many threads
(number of threads depends on the configuration). The problem is when I try to start my service it won't start, and threads won't start. When I try to run this app as windows app, threads start without a problem.
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
public class EngineServer:ServiceBase
{
private IInterfaceLog log;
#region Constructor / Destructor
public EngineServer():base()
{
InitializeComponent();
this.log = new LogProvider();
}
private void InitializeComponent()
{
this.ServiceName = "RbInterface_engine_servic
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
}
base.Dispose( disposing );
}
#endregion
static void Main(string[] args)
{
ServiceBase.Run(new EngineServer());
}
protected override void OnStart(string[] args)
{
Engine.Instance.EngineMess
Engine.Instance.Start();
}
protected override void OnStop()
{
Engine.Instance.Stop();
}
[MethodImpl(MethodImplOpti
private void OnEngineMessage(string message, string threadId, int cycleCount, string instanceType, string assembly, string function)
{
//Do some logging
}
}
From the above code, Engine.Instance.Start() function has the following code, the funny part if I comment out:
//Engine.Instance.EngineMe
//Engine.Instance.Start();
it works without a problem, it doesn't start any threads, but service starts.
[MethodImpl(MethodImplOpti
public void Start()
{
this.ReloadConfig();
lock(syncObject)
this.runningThreads.Clear(
foreach(string threadId in this.threadsToExecute.Keys
{
Thread newThread = new Thread(new ThreadStart(this.RunThread
newThread.Priority = ThreadPriority.Lowest;
newThread.Name = threadId;
lock(syncObject)
this.runningThreads[thread
}
lock(syncObject)
this.isContinue = true;
this.PostMessage("Starting
lock(syncObject)
foreach(Thread thread in this.runningThreads.Values
thread.Start();
}
Any help is highly appreciated