A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
I have a vb.net code which reads from a text file all network locations and then calculated the MD5 hash of those files and then further write hash values to output.txt file ... Program stops working after 500 lines and throw following error ... following is the code and error messages
CODE:
Dim sNames As String() = {"A"} System.Threading.Tasks.Parallel.For(0, sNames.Count, Sub(i) For Each line As String In lines file.Write(MD5(line, 2)) file.Write("@") file.WriteLine(line) ' i += 1 ProgressBar1.Value += 1 Next End Sub) file.Close()
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dllA first chance exception of type 'System.ArgumentException' occurred in mscorlib.dllA first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dllA first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dllA first chance exception of type 'System.ArgumentException' occurred in mscorlib.dllA first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dllA first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dllA first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dllA first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dllA first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dllA first chance exception of type 'System.ArgumentException' occurred in mscorlib.dllThe program '[11208] WindowsApplication1.vshost.exe' has exited with code 0 (0x0).
do you close the files afetr they were written? windows applications have a maximum of 512 file handles that can be opened same time. this maximum can be increased to 2048 (programmatically) but it is better to practice a proper closing of your files.
Sara
CalmSoul
ASKER
sarabande:
Interesting, so where should I close them with in the loop after every line write?