473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

thread starting then stopping immediately - access to socket denied?

I have a windows service that creates a monitor thread which in turn
creates 4 worker threads. Each thread is based upon a derived class
(HL7Listener) of the TcpListener class. When running this service on
my workstation I have no problems whatsoever. I then deployed this to
another server and cannot open any of the sockets. Troubleshooting
this issue I've discovered that the 4 threads do successfully enter
the HL7Listener constructor. Unfortunately the method called from
ThreadStart never gets executed. My monitor thread checks the status
of each worker thread every 10 seconds and the threadstate for each
thread is set to running temporarily.

I'm totally baffled and frustrated. This is my first attempt at
multi-threading. My logic is based upon solid examples. Again,
everything works fine on my workstation.

I've set each thread principal to the WindowsPrincipal and am writing
to the event log within the various methods to determine exactly where
my problem might lie. I'm catching every possible exception and
nothing is being thrown.

please help!
Nov 15 '05 #1
3 2054
"karl" <ka**********@tricaresw.af.mil> wrote in message
news:d2**************************@posting.google.c om...
I have a windows service that creates a monitor thread which in turn
creates 4 worker threads. Each thread is based upon a derived class
(HL7Listener) of the TcpListener class. When running this service on
my workstation I have no problems whatsoever. I then deployed this to
another server and cannot open any of the sockets. Troubleshooting
this issue I've discovered that the 4 threads do successfully enter
the HL7Listener constructor. Unfortunately the method called from
ThreadStart never gets executed. My monitor thread checks the status
of each worker thread every 10 seconds and the threadstate for each
thread is set to running temporarily.

I'm totally baffled and frustrated. This is my first attempt at
multi-threading. My logic is based upon solid examples. Again,
everything works fine on my workstation.

I've set each thread principal to the WindowsPrincipal and am writing
to the event log within the various methods to determine exactly where
my problem might lie. I'm catching every possible exception and
nothing is being thrown.

please help!


You aren't running the service under "LocalSystem" account are you? You
need to setup a domain user account to get access to anything non-trivial in
the system. Go to the Services Administrative Tool and then click on
Properties for your service. Then go to the LogOn tab and enter a domain
user account. Then try to run your service. It should work. In the
meantime check this out:
http://msdn.microsoft.com/library/de...on_account.asp
Nov 15 '05 #2


----- karl wrote: ----
I've set each thread principal to the WindowsPrincipal and am writin
to the event log within the various methods to determine exactly wher
my problem might lie. I'm catching every possible exception an
nothing is being thrown


are you absolutely sure that is the case. are you catching and logging exceptions in each worker thread individually? because monitor thread will not be able to catch exceptions thrown in the worker threads. otherwise, don't know what to tell you without examining the code.
Nov 15 '05 #3
below is the method that gets called within the ThreadStart. Also, I
forgot to mention that the HL7Listener class has a property called
ExceptionString that gets populated with whatever exception that is
handled. The monitor thread then checks to see if the ExceptionString
is set so that it can report it to the eventlog, abort the thread, reset
the ExceptionString and start a new thread. Hopefully this code formats
correctly when I submit this reply.

thanks again for the help!

public void StartListening()
{
EventLog.WriteEntry("ICDB", "entered StartListening() on port " +
this._port);
while (true)
{
EventLog.WriteEntry("ICDB", "Listening on port " + this._port);

if (!this.Active)
{
try
{
this.Start();
//Console.WriteLine("Listening for a connection...");

}
catch (SocketException se)
{
this.ExceptionString = se.ToString();
}
catch (Exception e)
{
this.ExceptionString = e.ToString();
}
}

try
{
if (!this._clientConnected)
{
client = this.AcceptSocket();
this._clientConnected = true;
}
//Console.WriteLine("Connection accepted...");
ns = new NetworkStream(client);

bool bState, bConnected = true;

while (bConnected)
{
if (ns.DataAvailable) this.GetMessage();

bState = client.Poll(1, SelectMode.SelectRead);

if (bState && client.Available == 0)
bConnected = false;
else
bConnected = true;
System.Threading.Thread.Sleep(100);
}
}
catch (ThreadAbortException)
{
this.ExceptionString = "Thread signalled to abort";
//Console.WriteLine("Thread Interrupted. Exiting thread ");
}
catch (ObjectDisposedException)
{
this.ExceptionString = "Socket closed by client.";
}
catch (SocketException se)
{
this.ExceptionString = se.ToString();
}
catch (Exception e)
{
this.ExceptionString = e.ToString();
}
finally
{
if (this.ns != null)
this.ns.Close();
if (this.client != null)
{
this.client.Close();
this._clientConnected = false;
}

if (this.DBConnected)
{
this.OraConn.Close();
this.OraConn.Dispose();
}

EventLog.WriteEntry("ICDB", "Finally Leaving StartListening() on
port " + this._port);
}
}
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ajay | last post by:
hi! i have a main application which is run through a GUI. the GUI has a function 'start server' which starts a server in another thread and a stop function which should stop this server. the...
9
by: phil | last post by:
And sorry I got ticked, frustrating week >And I could help more, being fairly experienced with >threading issues and race conditions and such, but >as I tried to indicate in the first place,...
2
by: Bruce Vander Werf | last post by:
How can I cleanly stop a thread that is currently blocking on Socket.Receive? I don't want to use Thread.Abort, because I would like the thread method to exit cleanly, and the same code must run...
10
by: Nikola Skoric | last post by:
Hello there, Lets say I have something like this in my Mother Of All Threads: Thread thread1 = new Thread(new ThreadStart(this.run)); thread1.Start(); //some unimportant code...
7
by: Droopy | last post by:
Hi, I don't understand why sometimes, a loop running in a thread takes much more time than usual. I have a thread that must call each 20 ms a C++ unmanaged function. I made a C++ managed...
5
by: taylorjonl | last post by:
I am completely baffled. I am writting a daemon application for my work to save me some time. The application works fine at my home but won't work right here at work. Basically I have a...
5
by: zxo102 | last post by:
Hi, I am doing a small project using socket server and thread in python. This is first time for me to use socket and thread things. Here is my case. I have 20 socket clients. Each client send a...
11
by: Jon Slaughter | last post by:
Is there any way to start a terminated thread without using a pool or creating a new thread object? void counter() { clicks = 0; clock.Start(); while (counterActive) { clicks++;
18
by: =?Utf-8?B?VGhlU2lsdmVySGFtbWVy?= | last post by:
Because C# has no native SSH class, I am using SharpSSH. Sometimes, for reasons I do not know, a Connect call will totally lock up the thread and never return. I am sure it has something to do...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.