Thread don't start

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello. I have a c# service with four threads. Sometimes one of them just
don't start, I don't know why. It happened with any of the four threads, and
just in production environment, not in development environment.

Any idea? Best regards,
Ray
 
Ray said:
Hello. I have a c# service with four threads. Sometimes one of them just
don't start, I don't know why. It happened with any of the four threads, and
just in production environment, not in development environment.

Well, it's hard to say anything without seeing some code.

Have you cut down the program in phases to find a minimal one that
fails? How are you diagnosing that the thread doesn't start?
 
Code is something like this:

public class MyService : System.ServiceProcess.ServiceBase
{

private ProcA oProcA;
private Thread tProcA;
private ProcB oProcB;
private Thread tProcB;

protected override void OnStart(string[] args)
{
// Process A
oProcA = new ProcA();
tProcA = new Thread(new ThreadStart(oProcA.DoProcA));
tProcA.Start();

// Process B
oProcB = new ProcB();
tProcB = new Thread(new ThreadStart(oProcB.DoProcB));
tProcB.Start();
}
}

public class ProcA
{
private System.IO.StreamWriter sw;

public ProcA()
{}

public void DoProcA()
{
for (int i=1; i<300; i++)
{
sw = System.IO.File.AppendText("c:\testA.txt");
sw.WriteLine("running ProcA");
Thread.Sleep(1000);
}
}
}

public class ProcB
{
private System.IO.StreamWriter sw;

public ProcB()
{}

public void DoProcB()
{
for (int i=1; i<300; i++)
{
sw = System.IO.File.AppendText("c:\testB.txt");
sw.WriteLine("running ProcB");
Thread.Sleep(1000);
}
}
}

Regards.
 
Code is something like this:

<snip>

And the process definitely has access to write to everything it needs
to?
How quickly do you get to find out that a thread has started?
Can you be sure that the OnStart code has been run completely?

Jon
 

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

Similar Threads

about understanding Threads 7
threading 2
threads 1
Threads, delegates and invoke function with 2.0 7
Multi-Threaded App 3
force kill thread 6
Thread 1
GUI Thread - Is cross-thread operation really bad? 19

Back
Top