G
Guest
I have a small problem with my windows service. The first time I start the service everything works the way it's suppose to, but randomly the service fails. The jist of the service is to use the filewatcher component to watch a directory. On create only, the service will read the small XML file, process the information. Once the file is finished processing the information, it should copy the file to another directory and delete the original.
After the first file is processed by the filewatcher, the following error message occurs on all the files after "The process cannot access the file "C:\test\rk.xml" because it is being used by another process".
Can someone tell me why the file is not being released? Any help would be greatly appreciated! Please see the code snippet below:
protected void fsw_Created (
object sender, System.IO.FileSystemEventArgs e)
{
XmlTextReader reader = new XmlTextReader (e.FullPath);
//Declare Array
String[] a = new String[10];
int arrayCounter = 0;
try
{
while (reader.Read())
{
switch (reader.NodeType)
{
// case XmlNodeType.Element: // The node is an element.
// Console.Write("<" + reader.Name);
// Console.WriteLine(">");
// break;
case XmlNodeType.Text: //Display the text in each element.
// Console.WriteLine (reader.Value);
a[arrayCounter] = reader.Value;
arrayCounter += 1;
break;
// case XmlNodeType.EndElement: //Display the end of the element.
// Console.Write("</" + reader.Name);
// Console.WriteLine(">");
// break;
//End of switch
}
//End of while
}
if (reader.EOF == true)
{
reader.Close();
}
string prcinstance = a[0];
string[] actionNames = new string[a.Length -1];
Array.Copy(a,1,actionNames,0,9);
//File.Delete(e.FullPath);
File.Copy(e.FullPath,"c:\\" + e.Name,true);
EventLog.WriteEntry("Monitor", e.Name + " has been copied");
if (File.Exists("c:\\" + e.Name))
{
File.Delete(e.FullPath);
EventLog.WriteEntry("Monitor", e.Name + " has been copied");
}
}
catch (Exception ex)
{
EventLog.WriteEntry("Monitor - Error", ex.Message);
}
}
Thanks,
Ron
After the first file is processed by the filewatcher, the following error message occurs on all the files after "The process cannot access the file "C:\test\rk.xml" because it is being used by another process".
Can someone tell me why the file is not being released? Any help would be greatly appreciated! Please see the code snippet below:
protected void fsw_Created (
object sender, System.IO.FileSystemEventArgs e)
{
XmlTextReader reader = new XmlTextReader (e.FullPath);
//Declare Array
String[] a = new String[10];
int arrayCounter = 0;
try
{
while (reader.Read())
{
switch (reader.NodeType)
{
// case XmlNodeType.Element: // The node is an element.
// Console.Write("<" + reader.Name);
// Console.WriteLine(">");
// break;
case XmlNodeType.Text: //Display the text in each element.
// Console.WriteLine (reader.Value);
a[arrayCounter] = reader.Value;
arrayCounter += 1;
break;
// case XmlNodeType.EndElement: //Display the end of the element.
// Console.Write("</" + reader.Name);
// Console.WriteLine(">");
// break;
//End of switch
}
//End of while
}
if (reader.EOF == true)
{
reader.Close();
}
string prcinstance = a[0];
string[] actionNames = new string[a.Length -1];
Array.Copy(a,1,actionNames,0,9);
//File.Delete(e.FullPath);
File.Copy(e.FullPath,"c:\\" + e.Name,true);
EventLog.WriteEntry("Monitor", e.Name + " has been copied");
if (File.Exists("c:\\" + e.Name))
{
File.Delete(e.FullPath);
EventLog.WriteEntry("Monitor", e.Name + " has been copied");
}
}
catch (Exception ex)
{
EventLog.WriteEntry("Monitor - Error", ex.Message);
}
}
Thanks,
Ron