By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Thread don't start

P: n/a
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

Sep 17 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Ray <Ra*@discussions.microsoft.comwrote:
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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 17 '07 #2

P: n/a
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.

"Jon Skeet [C# MVP]" wrote:
Ray <Ra*@discussions.microsoft.comwrote:
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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 18 '07 #3

P: n/a
On Sep 18, 1:02 am, Ray <R...@discussions.microsoft.comwrote:
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

Sep 18 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.