Hello Guys
I have following code that based on how big the file is comes up with the milli seconds (int) that my process would wait for. For some reason some of the file lengths are coming out to zero. Can someone point out if there is flaw in the logic that causes
this? I think the fileInfo length is zero because in my event viewer I see that 0 ms was allocated for this process. If my understanding of math.ceiling is correct, this is possible only if length is zero ( for the code below ).
Please help!!!
private int GetTimeForCurrentFile(string currentFileToProcess)
{
long fileSize = new FileInfo(System.IO.Path.Combine(FSWatcher.Path, currentFileToProcess)).Length;
int multiplyFactor = (int)Math.Ceiling(Convert.ToDouble(fileSize) / 1000000);
return multiplyFactor * 10 * 60000;
}
This method is getting called from the following code:
Process process = new Process();
try
{
process.StartInfo.FileName = ProgramToStart;
process.StartInfo.Arguments = currentFileToProcess;
process.Start();
int timeToWait = GetTimeForCurrentFile(currentFileToProcess);
string logEntry = string.Format("File: {0} Created. Total time allocated {1} ms.", currentFileToProcess, timeToWait);
EventLog.WriteEntry("Directory Monitor", logEntry);
process.WaitForExit(timeToWait);
if (process.HasExited == false)
{
EventLog.WriteEntry("Directory Monitor", "File: " + currentFileToProcess + " not processed as it took more than allocated time. The process was terminated.");
process.Kill();
}
DV