I created a service that watches a folder, processes the files that gets dumped into it, then after processing, it moves the files to another folder.
So i copy a number of files to this folder, and every now and then, i get an exception stating that i cannot gain access to this file, then it goes through the loop again, until it can process it. But that is not the issue, I get the exception but the service remains alive, and the it does what it is supposed to do with the files...it works perfectly.
The problem: When I install this service on a other machine, it processes say...10 files perfectly, but not more, when it gets the exception, the service dies.
Both machine are using .net framework 4 and both have the necessary files. Can anyone point me in the right direction as to what the problem can be?
I have tried sleep and all these things...but I dont think that it's really needed if my machine can do this task effortlessly.
try
{
if (System.IO.File.Exists(e.FullPath))
{
// System.Threading.Thread.Sleep(100);
System.IO.StreamReader inputfile = new System.IO.StreamReader(e.FullPath);
do
{
// System.Threading.Thread.Sleep(5000);
// FileName = e.FullPath.ToString().Remove(0, 24);
Ticket = e.Name.ToString(); //FileName.Remove(8, 4);
Record = inputfile.ReadLine();
if (Record == null)
break;
if (Record.Contains("ATMID") && i == 0)
{
ATMID = Record.Remove(0, 8);
i++;
}
if (Record.Contains("CODE") && i == 1)
{
StatusCode = Record.Remove(0, 7);
i++;
}
if (Record.Contains("DESCRIPTION") && i == 2)
{
EventDescription = Record.Remove(0, 14);
i++;
}
if (Record.Contains("ACTION") && i == 3)
{
ActionCode = Record.Remove(0, 14);
}
if (Record.Contains("START"))
{
temp = Record.Remove(0, 7);
TimeofEvent = temp.Remove(0, 11);
DateofEvent = temp.Substring(1, 10);
DateofEvent = DateofEvent.Replace("/", "");
}
//time.Interval = 60000;
//time.Enabled = true;
// System.Threading.Thread.Sleep(100);
} while (Record != null);
inputfile.Close();
SNMPMessageSend(ATMID, StatusCode, EventDescription, ActionCode, TimeofEvent, DateofEvent, Ticket, e);
}
}
catch (System.Exception ex)
{
File.Create(@"C:\Work Tasks\exception.txt").Close();
File.WriteAllText(@"C:\Work Tasks\exception.txt", ex.Message);
}