Executing 2 Threads



Hello Everyone,

I’m having a bit of difficulty with a threading scenario.
Basically I’m creating 2 threads and trying to execute them one after the
other.
The problem is that the second thread never fires.

My environment is a bit complex, and I’m wondering of that’s what is working
against me. At the top level I have s series of windows services running
which all operate independent of each other. Each of these services operates
on a timer and with each tick event will try to create an instance of a new
“Engine” class. The “Engine” classes that are being created further
instantiate “Helper” classes.

Each “Helper” supports a “Start_Module” method which takes no parameters.
When the “Start_Module” method is called the “Helper” class will perform
various tasks such as updating records in SQL Server and or formatting data.

Each of my “Engine” classes also support a method called “Start_Engine”
which is responsible for instantiating my “Helper” classes.

To further complicate things, each “Engine” class also supports “Can_Stop”
Boolean method which will look at of each of it’s child threads to see if the
Engine can be unloaded from memory by the controlling Windows service.

So my main problem is that once I create and start the “Engine” class it
will successfully create the 1st thread, but never get around to starting the
2nd thread.

I appreciate any help or advice that you can give me on this matter.
Thanks,

Johnathan Rossitter

Here is an example of the code I’m trying to make work:

using System;
using System.Threading;
namespace Utility
{
public class Engine1: Engine
{
Thread[] MyThreads = new Thread[2];

private Helper1 H1;
private Helper2 H2

public Engine1()
{
}

private void Checker()
{
H1 = new H1();
H1.Start_Helper();
}

private void Cleaner()
{
H2 = new H2();
H2.Start_Helper();
}

public override bool Start_Engine()
{
MyThreads[0] = new Thread(new ThreadStart(Checker));
MyThreads[1] = new Thread(new ThreadStart(Cleaner));

MyThreads[0].Start();
MyThreads[1].Start();

return true;
}

public override bool Can_Stop()
{
bool RetVal = true;
for(int i = 0; i < MyThreads.Length; i++)
{
if(MyThreads[i].IsAlive == true)
{
RetVal = false;
}
}

return RetVal;
}
}

public class Helper1:Helper
{
public override bool Start_Module()
{
//Do SQL Stuff
//Do Formatting Stuff
return false;
}

public Helper1()
{
}
}

public class Helper2:Helper
{
public override bool Start_Module()
{
//Do SQL Stuff
//Do Formatting Stuff
return false;
}

public Helper2()
{
}
}

}


.



Relevant Pages

  • Re: Thread termination
    ... > I would like to execute some code when a thread terminates, ... public class ThreadStarterWithFinish ... static void Normal() ...
    (microsoft.public.dotnet.general)
  • Re: using windows services
    ... is why the task scheduler exists...for this very kind of batch processing. ... > also want to execute it every night at 12. ... > using windows services only once every day at 12 in the night. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Please help with thread problem
    ... I need to execute a program from an other and I use this method: ... public class P1 { ... but I cannot figure out how to port this in my ... Sandra ...
    (comp.lang.java.programmer)
  • Please help with thread problem
    ... I need to execute a program from an other and I use this method: ... public class P1 { ... but I cannot figure out how to port this in my ... Sandra ...
    (comp.lang.java.help)
  • using windows services
    ... Can anyone guide how to execute this program ... using windows services only once every day at 12 in the night. ... to code samples would be a great help. ... Srinivas ...
    (microsoft.public.dotnet.framework.aspnet.webservices)