Filesystemwatcher causes exception.
-
Hello friends. my question is very short. I only used one filesystemwather and nothing else. And used its created method. But when i send a file into the folder, it throws this error:"Exception has been thrown by the target of an invocation." on this line: Application.Run(new Form1()); Do you know why?
-
Hello friends. my question is very short. I only used one filesystemwather and nothing else. And used its created method. But when i send a file into the folder, it throws this error:"Exception has been thrown by the target of an invocation." on this line: Application.Run(new Form1()); Do you know why?
the exception is not really on that line. its somewhere inside the Form1 class. can you post the complete exception stack ? try to debug your application step by step you can able to track down this error.
-
Hello friends. my question is very short. I only used one filesystemwather and nothing else. And used its created method. But when i send a file into the folder, it throws this error:"Exception has been thrown by the target of an invocation." on this line: Application.Run(new Form1()); Do you know why?
-
the exception is not really on that line. its somewhere inside the Form1 class. can you post the complete exception stack ? try to debug your application step by step you can able to track down this error.
Yes you are right. This is what i found in intellitrace: Exception:Thrown: "The process cannot access the file 'd:\deneme\OCTOPUSxml-66907571 - Copy.xml' because it is being used by another process." (System.IO.IOException) A System.IO.IOException was thrown: "The process cannot access the file 'd:\deneme\OCTOPUSxml-66907571 - Copy.xml' because it is being used by another process." Exception:Thrown: "Exception has been thrown by the target of an invocation." (System.Reflection.TargetInvocationException) A System.Reflection.TargetInvocationException was thrown: "Exception has been thrown by the target of an invocation." In created method of filewatcher, i have these codes: XmlDocument xdc = new XmlDocument(); xdc.Load(e.FullPath); Somehow, grasping the file by filewatcher and loading by xmldocument occur almost at the same time. To be sure i changed the code as : XmlDocument xdc = new XmlDocument(); System.Threading.Thread.Sleep(1000); xdc.Load(e.FullPath); System.Threading.Thread.Sleep(1000); I know this is not professional but now it is working :)
-
Yes you are right. This is what i found in intellitrace: Exception:Thrown: "The process cannot access the file 'd:\deneme\OCTOPUSxml-66907571 - Copy.xml' because it is being used by another process." (System.IO.IOException) A System.IO.IOException was thrown: "The process cannot access the file 'd:\deneme\OCTOPUSxml-66907571 - Copy.xml' because it is being used by another process." Exception:Thrown: "Exception has been thrown by the target of an invocation." (System.Reflection.TargetInvocationException) A System.Reflection.TargetInvocationException was thrown: "Exception has been thrown by the target of an invocation." In created method of filewatcher, i have these codes: XmlDocument xdc = new XmlDocument(); xdc.Load(e.FullPath); Somehow, grasping the file by filewatcher and loading by xmldocument occur almost at the same time. To be sure i changed the code as : XmlDocument xdc = new XmlDocument(); System.Threading.Thread.Sleep(1000); xdc.Load(e.FullPath); System.Threading.Thread.Sleep(1000); I know this is not professional but now it is working :)
Sleep is not the right choice. can you paste the code on how you initialize the file watcher instance. I guess its FileCreated event you are watching,while other application create and manage the file you are trying to load this in your form.
-
Yes you are right. This is what i found in intellitrace: Exception:Thrown: "The process cannot access the file 'd:\deneme\OCTOPUSxml-66907571 - Copy.xml' because it is being used by another process." (System.IO.IOException) A System.IO.IOException was thrown: "The process cannot access the file 'd:\deneme\OCTOPUSxml-66907571 - Copy.xml' because it is being used by another process." Exception:Thrown: "Exception has been thrown by the target of an invocation." (System.Reflection.TargetInvocationException) A System.Reflection.TargetInvocationException was thrown: "Exception has been thrown by the target of an invocation." In created method of filewatcher, i have these codes: XmlDocument xdc = new XmlDocument(); xdc.Load(e.FullPath); Somehow, grasping the file by filewatcher and loading by xmldocument occur almost at the same time. To be sure i changed the code as : XmlDocument xdc = new XmlDocument(); System.Threading.Thread.Sleep(1000); xdc.Load(e.FullPath); System.Threading.Thread.Sleep(1000); I know this is not professional but now it is working :)
FileSystemWatcher doesn't "grab" files. It doesn't touch them at all. The file is either being held open by your process using some other method, or some other process has the file open and locked, like something that outputs the file?? Or some editor??
A guide to posting questions on CodeProject[^]
Dave Kreskowiak