Threading question

  • Thread starter Thread starter Richard Blewett [DevelopMentor]
  • Start date Start date
R

Richard Blewett [DevelopMentor]

You don't show the infrastructure that binds all this together. Is it possible the method that wraps #) final is not getting called. Have you put in diagnostic tracing to see if the method it getting called; if the directory checks are returning 0; if the thread starts but doesn't do anything?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

I have the following code in a windows service, when I start the windows
service process1 and process2 work fine , but final process (3) doesnt get
called. i stop and restart the windows service and the final process(3) gets
called. what am I doing wrong with the threading? by the way
Directory.GetFiles(IncomingXMLPath1).Length is some global outcome from
process 1.
 
CK said:
I have the following code in a windows service, when I start the windows
service process1 and process2 work fine , but final process (3) doesnt get
called. i stop and restart the windows service and the final process(3) gets
called. what am I doing wrong with the threading? by the way
Directory.GetFiles(IncomingXMLPath1).Length is some global outcome from
process 1.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

(It's worth trying to reproduce it in a console app, btw - they're much
easier to work with.)
 
I have the following code in a windows service, when I start the windows
service process1 and process2 work fine , but final process (3) doesnt get
called. i stop and restart the windows service and the final process(3) gets
called. what am I doing wrong with the threading? by the way
Directory.GetFiles(IncomingXMLPath1).Length is some global outcome from
process 1.

Thanks

1)
m_threadNewClaimInstitutional = new Thread(new
System.Threading.ThreadStart(process1));

m_threadNewClaimInstitutional.Start();

2)

m_ThreadNewClaimProfessional= new Thread(new
System.Threading.ThreadStart(process2));

m_ThreadNewClaimProfessional.Start();

//when all the files have been processed in both the process1 and process2
directories

//then is the final process

#)final

if(Directory.GetFiles(IncomingXMLPath1).Length==0 &&
Directory.GetFiles(IncomingXMLPath2).Length==0)

{

m_ThreadFinall = new Thread(new System.Threading.ThreadStart(process3));

m_ThreadFinall.Start();

}
 
To add my penny's worth, I'd not place any code into a windows service apart
from calling a class library, that does what you want your windows service
to do.

By extracting the "core" of your application, and simply placing "Start()"
and "Stop()" methods in your class library you can then put any front end on
your application. This is technique comes into its own when your debugging
it, because you can simply place a front end console app (or simple dialog)
to run the code, rather than trying to debug a running service.

HTH.
 
How are you waiting for the first two threads to complete? If you do

m_threadNewClaimInstitutional.Join();
m_ThreadNewClaimProfessional.Join();

At the start of the 3rd thread, it will not attempt to check for the lack of files until the first two threads have finished. You could also do the same thing with two ManualResetEvents and WaitHandleWaitAll

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

I have the following code in a windows service, when I start the windows
service process1 and process2 work fine , but final process (3) doesnt get
called. i stop and restart the windows service and the final process(3) gets
called.
The thing is I dont want to restart the service I just waant process 1 and 2
take place and after 1 and 2 are done , process 3 to take over.
what am I doing wrong with the threading? by the way
Directory.GetFiles(IncomingXMLPath1).Length is some global outcome from
process 1.
note process 1 and 2 do the exact same thing : I include the code for
process 1)
 
I have the following code in a windows service, when I start the windows
service process1 and process2 work fine , but final process (3) doesnt get
called. i stop and restart the windows service and the final process(3) gets
called.
The thing is I dont want to restart the service I just waant process 1 and 2
take place and after 1 and 2 are done , process 3 to take over.
what am I doing wrong with the threading? by the way
Directory.GetFiles(IncomingXMLPath1).Length is some global outcome from
process 1.
note process 1 and 2 do the exact same thing : I include the code for
process 1)

this is written in a class , windows services just calls it.

Thanks

internal void StartService()

{

if (!ServiceRunning)

{


m_threadNewClaimInstitutional = new Thread(new
System.Threading.ThreadStart(process1));
m_threadNewClaimInstitutional.Start();


m_ThreadNewClaimProfessional= new Thread(new
System.Threading.ThreadStart(process2));
m_ThreadNewClaimProfessional.Start();

//when all the files have been processed in both the process1 and process2
directories

//then is the final process

#)final

if(Directory.GetFiles(IncomingXMLPath1).Length==0 &&
Directory.GetFiles(IncomingXMLPath2).Length==0)

{
m_ThreadFinall = new Thread(new System.Threading.ThreadStart(process3));
m_ThreadFinall.Start();
}

}
}

private void Process1()

{

//Instantiate the Converter class

Newclass objP= new NewClass();

//Process the Files one by one

while(Directory.GetFiles(IncomingXMLPathPLength>0)

{

if(Directory.Exists(IncomingXMLPathP) && Directory.Exists(PathIntermediate))

{

//Get the File in the directory

DirectoryInfo dir = new DirectoryInfo(IncomingXMLPathP);

FileInfo[] xmlfiles = dir.GetFiles("*.xml");

Thread.Sleep(1000);

foreach( FileInfo file in xmlfiles)

{


string strH="";

string InternalTransactionID="";

StreamReader sr = File.OpenText(file.FullName);

string data= sr.ReadToEnd();


strH= objP.ConvertNewCt(data,out InternalTransactionID);

FileInfo outputFile = new
FileInfo(PathIntermediate+InternalTransactionID+".clm");

StreamWriter strWriter =new StreamWriter(File.Open(PathIntermediate+
InternalTransactionID +".clm",FileMode.Create, FileAccess.Write ));

strWriter.Flush();

strWriter.Write(strHMI.ToString());


strWriter.Close();

sr.Close();

file.Delete();

}

}

}

}
 
Back
Top