Threading question

05/01/2005 - 09:11 por CK | Informe spam
I have the following code in a windows service, when I start the windows
service process1 and process2 work fine ,When process 1) and 2) get
completed process 3) starts and sofar so good. the problem is if the files
in process 1) are all processed and we are in the middle of process 2) , at
this point if i coppy a file to the directory for process 1) then this file
never gets processed and we never enter process 3) . How can I fix this
issue?
and How can I stop the service when process 3) has processed all the files?

Thanks in advance

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

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


//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();

}


//this is the code for the process 1) , process 2) is similar
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="";

//Opens an existing UTF-8 encoded text file for reading.

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();

}

}

}

}

Preguntas similare

Leer las respuestas

#1 Octavio Hernandez
05/01/2005 - 11:46 | Informe spam
I'd try to substitute the call to GetFiles() and the subsequent loop for
PInvoke calls to FindFirstFile/FindNextFile which are aware of dynamic
changes in directories. See the details for the calls at www.pinvoke.net.

Regards - Octavio

"CK" escribió en el mensaje
news:
I have the following code in a windows service, when I start the windows
service process1 and process2 work fine ,When process 1) and 2) get
completed process 3) starts and sofar so good. the problem is if the files
in process 1) are all processed and we are in the middle of process 2) ,
at this point if i coppy a file to the directory for process 1) then this
file never gets processed and we never enter process 3) . How can I fix
this issue?
and How can I stop the service when process 3) has processed all the
files?

Thanks in advance

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

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


//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();

}


//this is the code for the process 1) , process 2) is similar
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="";

//Opens an existing UTF-8 encoded text file for reading.

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();

}

}

}

}

email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida