ThreadStart not called on some servers

S

StefanS

Hi all

I'm stuck with a problem and hope someone can provide some hints on
what I'm doing wrong.

All I want to do ist start a thread which will sleep until a specified
time and then wake up and do some stuff. (see reduced-to-the-max
sample code below)
The stange thing is, it works on my developer machine (Win XP) and on a
virtual machine (Win2003 Server) I use to test, but on the "real"
server (also Win2003) RunInNewThread ist never called, also the
ThreadState is "running".
There are no exceptions, no entries in the event log.. nothing.

All machines have .NET 2.0 installed. The two working systems are
running with the default-configuration. On the target server I'm not so
sure about that, but I need to tell the administrator where to start
searching since he knows even less than I do.

Hope someone can help me on this.
TIA
Stefan

private void Test_StartThread()
{
try
{
DateTime threadStartTime = DateTime.Now.AddSeconds(30.0);
ThreadStart starter = delegate {
TestClass.RunInNewThread(threadStartTime); };
Thread t = new Thread(starter);
t.Start();
Console.Write("Thread state : " + t.ThreadState.ToString());
}
catch(Exception ex)
{
Console.Write("Starting thread falied");
}
}


public class TestClass
{
public static void RunInNewThread(DateTime pStartTime)
{
Console.Write("starting thread to run at " +
pStartTime.ToString());
// in real app, thread will sleep until pStartTime and then do some
stuff
// Thread.Sleep(pStartTime.Subtract(DateTime.Now);
//
// -- do something
}
}
 
P

pranshu

Hi Stefan,
All I want to do ist start a thread which will sleep until a specified
time and then wake up and do some stuff.

Is your application a console/windows application, a asp.net
application or a windows service?
I have not had this problem in a windows service and I have never
tried using such thread within IIS, or even within a windows
application so possibly I have no solution for it.

But just to jog your mind a bit, I would also suggest that you consider
following
1) using a Timer instead of sleeping thread.
2) use windows scheduler to invoke this thread / or a this thread
refactored into a console application. You can also consider making it
a MS SQL Server job ( Helpful if you are looking at clustered / failed
over configurations for server side jobs).


Pranshu
 
S

StefanS

Hi Pranshu

thanks for your response. I'm dealing with a ASP.NET application and
since it hosted by another company I do not have priviledges to run
windows apps/services or ti initiate SQL Server jobs.
But I will try the approach with the Timer, I only knew that as a
client-Control and was not aware that it also exists for webapps.

Stefan
 

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