windows service not starting threads on newly deployed server

K

karl

I have a windows service that kicks off a 'monitor' thread which in
turn kicks off 4 additional threads. These 4 threads basically are
listen on a designated socket and report back any errors (exceptions)
to the monitor thread.

Of course, all works well on my box. Yesterday I installed the .NET
Framework 1.1 on a new server and then installed my service. It
appears that everything is starting but when I perform a netstat - a
searching for my 4 ports, I don't see them 'listening'. Via Task
Manager... I added the Thread Count column and see that 6 threads are
running. I compare this to my box and 11 threads are running. Not
sure if this even applies but I don't know how to remotely trouble
shoot this issue. I really need to figure out why these 4 threads are
starting. thanks for the help!

code snippet...

Also, this is portion of the code so if it's confusing let me know.

protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
this._serviceRunning = true;
ThreadStart ts = new ThreadStart( this.Monitor );
Thread myWorkerThread = new Thread( ts );
myWorkerThread.Name = "MonitorThread";
myWorkerThread.Start();
}

within Monitor...

Hl7Listener[] hl7listener = new Hl7Listener[ls.Length];
threadArray = new Thread[ls.Length];

for (i=0;i<ls.Length;i++)
{
hl7listener = new Hl7Listener(ls.Port);
hl7listener.Priority = ls.Priority;
hl7listener.SiteMsgPrefix = ls.MsgPrefix;
threadArray = new Thread(new
ThreadStart(hl7listener.StartListening));
threadArray.Name = "HL7port"+Convert.ToString(ls.Port);
threadArray.IsBackground = true;
threadArray.Start();
this.eventLog1.WriteEntry("Listener thread started on port " +
Convert.ToString(ls.Port), EventLogEntryType.Information);
}

// member variable set to false within OnStop()
while (this._serviceRunning)
{
for (i=0;i<this.threadCount;i++)
{
if (hl7listener.ExceptionString != "")
{
this.eventLog1.WriteEntry("Exception handled on on thread port " +
Convert.ToString(ls.Port) +
hl7listener.ExceptionString, EventLogEntryType.Error);
hl7listener.ExceptionString = "";
if (threadArray.IsAlive)
{
hl7listener.Stop();
threadArray.Abort();
threadArray = null;
}
threadArray = new Thread(new
ThreadStart(hl7listener.StartListening));
threadArray.Name = "HL7port"+Convert.ToString(ls.Port);
threadArray.Start();
this.eventLog1.WriteEntry("Listener thread started on port " +
Convert.ToString(ls.Port), EventLogEntryType.Information);
}
}
Thread.Sleep(10000);
}
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi Karl,

I assume that you did a telnet to one of those ports, right?
Are none of them listening?
Did you check that there are not other services already listening on those
ports?
How are you creating the Listener object, maybe you have hardcoded your
box PC's IP. and tis is giving you problem as it;s not valid on the new
machine.

If none of the above solve your problem I would try to see if an exception
is being generated, The exception is not propagated to the parent thread so
you will have to put a mechanism in the thread code to check for them, maybe
write it to the log or dump it to a file.


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

karl said:
I have a windows service that kicks off a 'monitor' thread which in
turn kicks off 4 additional threads. These 4 threads basically are
listen on a designated socket and report back any errors (exceptions)
to the monitor thread.

Of course, all works well on my box. Yesterday I installed the .NET
Framework 1.1 on a new server and then installed my service. It
appears that everything is starting but when I perform a netstat - a
searching for my 4 ports, I don't see them 'listening'. Via Task
Manager... I added the Thread Count column and see that 6 threads are
running. I compare this to my box and 11 threads are running. Not
sure if this even applies but I don't know how to remotely trouble
shoot this issue. I really need to figure out why these 4 threads are
starting. thanks for the help!

code snippet...

Also, this is portion of the code so if it's confusing let me know.

protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
this._serviceRunning = true;
ThreadStart ts = new ThreadStart( this.Monitor );
Thread myWorkerThread = new Thread( ts );
myWorkerThread.Name = "MonitorThread";
myWorkerThread.Start();
}

within Monitor...

Hl7Listener[] hl7listener = new Hl7Listener[ls.Length];
threadArray = new Thread[ls.Length];

for (i=0;i<ls.Length;i++)
{
hl7listener = new Hl7Listener(ls.Port);
hl7listener.Priority = ls.Priority;
hl7listener.SiteMsgPrefix = ls.MsgPrefix;
threadArray = new Thread(new
ThreadStart(hl7listener.StartListening));
threadArray.Name = "HL7port"+Convert.ToString(ls.Port);
threadArray.IsBackground = true;
threadArray.Start();
this.eventLog1.WriteEntry("Listener thread started on port " +
Convert.ToString(ls.Port), EventLogEntryType.Information);
}

// member variable set to false within OnStop()
while (this._serviceRunning)
{
for (i=0;i<this.threadCount;i++)
{
if (hl7listener.ExceptionString != "")
{
this.eventLog1.WriteEntry("Exception handled on on thread port " +
Convert.ToString(ls.Port) +
hl7listener.ExceptionString, EventLogEntryType.Error);
hl7listener.ExceptionString = "";
if (threadArray.IsAlive)
{
hl7listener.Stop();
threadArray.Abort();
threadArray = null;
}
threadArray = new Thread(new
ThreadStart(hl7listener.StartListening));
threadArray.Name = "HL7port"+Convert.ToString(ls.Port);
threadArray.Start();
this.eventLog1.WriteEntry("Listener thread started on port " +
Convert.ToString(ls.Port), EventLogEntryType.Information);
}
}
Thread.Sleep(10000);
}
 
K

karl

Ignacio Machin \( .NET/ C# MVP \) said:
Hi Karl,

I assume that you did a telnet to one of those ports, right?
Are none of them listening?

I'm replacing a VB app that utilizes the same ports. I can start the
VB app and see that the ports are listening. I then shutdown the VB
app, confirm that nobody else is using the ports and then start up my
..NET app.
Did you check that there are not other services already listening on those
ports?
How are you creating the Listener object, maybe you have hardcoded your
box PC's IP. and tis is giving you problem as it;s not valid on the new
machine.

No hardcoding of any ip.
If none of the above solve your problem I would try to see if an exception
is being generated, The exception is not propagated to the parent thread so
you will have to put a mechanism in the thread code to check for them, maybe
write it to the log or dump it to a file.

My HL7Listener is derived from the TCPListener. I've added various
methods and fields. One field is an ExceptionString which stores any
exception that is thrown. The Monitor thread then checks to see if
this field has something in it so it can write it to the event log,
shutdown the listener, abort the thread and then create a new one.
Since this is my first attempt at working at threads, I realize that I
may be doing some overkill but I'm learning.

I'm using the InstallUtil.exe to install the service. I did find some
info about the .NET Security and found that there are special rules
relating to who can use a socket and such. Still investigating. I
was praying that I just needed to put something into the gac or
whatever it's called.

Oh yeah, I performed the same steps on another server and am having
the exact same problems. These servers are locked down due to C2
Certification so there may be something related to the accounts access
or the server access. Unknown.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

karl said:
I have a windows service that kicks off a 'monitor' thread which in
turn kicks off 4 additional threads. These 4 threads basically are
listen on a designated socket and report back any errors (exceptions)
to the monitor thread.

Of course, all works well on my box. Yesterday I installed the .NET
Framework 1.1 on a new server and then installed my service. It
appears that everything is starting but when I perform a netstat - a
searching for my 4 ports, I don't see them 'listening'. Via Task
Manager... I added the Thread Count column and see that 6 threads are
running. I compare this to my box and 11 threads are running. Not
sure if this even applies but I don't know how to remotely trouble
shoot this issue. I really need to figure out why these 4 threads are
starting. thanks for the help!

code snippet...

Also, this is portion of the code so if it's confusing let me know.

protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
this._serviceRunning = true;
ThreadStart ts = new ThreadStart( this.Monitor );
Thread myWorkerThread = new Thread( ts );
myWorkerThread.Name = "MonitorThread";
myWorkerThread.Start();
}

within Monitor...

Hl7Listener[] hl7listener = new Hl7Listener[ls.Length];
threadArray = new Thread[ls.Length];

for (i=0;i<ls.Length;i++)
{
hl7listener = new Hl7Listener(ls.Port);
hl7listener.Priority = ls.Priority;
hl7listener.SiteMsgPrefix = ls.MsgPrefix;
threadArray = new Thread(new
ThreadStart(hl7listener.StartListening));
threadArray.Name = "HL7port"+Convert.ToString(ls.Port);
threadArray.IsBackground = true;
threadArray.Start();
this.eventLog1.WriteEntry("Listener thread started on port " +
Convert.ToString(ls.Port), EventLogEntryType.Information);
}

// member variable set to false within OnStop()
while (this._serviceRunning)
{
for (i=0;i<this.threadCount;i++)
{
if (hl7listener.ExceptionString != "")
{
this.eventLog1.WriteEntry("Exception handled on on thread port " +
Convert.ToString(ls.Port) +
hl7listener.ExceptionString, EventLogEntryType.Error);
hl7listener.ExceptionString = "";
if (threadArray.IsAlive)
{
hl7listener.Stop();
threadArray.Abort();
threadArray = null;
}
threadArray = new Thread(new
ThreadStart(hl7listener.StartListening));
threadArray.Name = "HL7port"+Convert.ToString(ls.Port);
threadArray.Start();
this.eventLog1.WriteEntry("Listener thread started on port " +
Convert.ToString(ls.Port), EventLogEntryType.Information);
}
} Thread.Sleep(10000);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top