R4PM0NK3Y Posted December 11, 2003 Posted December 11, 2003 In my application, I am using a web client to download a file to the user's local machine. This works the first time, but after re-downloading I OCCASIONALLY recieve this run-time error: *****************START*********************** An unhandled exception has occurred in a component in your application. Click continue and application will ignore this error and attempt to continue. An exception occurred during a WebClient request. See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text ************** System.Net.WebException: An exception occurred during a WebClient request. ---> System.IO.IOException: The process cannot access the file "c:\Weather Bar\current.wbd" because it is being used by another process. at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at System.Net.WebClient.DownloadFile(String address, String fileName) --- End of inner exception stack trace --- at System.Net.WebClient.DownloadFile(String address, String fileName) at Weather_Bar.frmWeatherBar.GetCurrentWeather() in C:\CMPSC 115\Weather Bar\WeatherBar.vb:line 571 at Weather_Bar.frmWeatherBar.WeatherTimer_Tick(Object sender, EventArgs e) in C:\CMPSC 115\Weather Bar\WeatherBar.vb:line 679 at System.Windows.Forms.Timer.OnTick(EventArgs e) at System.Windows.Forms.Timer.Callback(IntPtr hWnd, Int32 msg, IntPtr idEvent, IntPtr dwTime) ************** Loaded Assemblies ************** mscorlib Assembly Version: 1.0.5000.0 Win32 Version: 1.1.4322.573 CodeBase: file:///c:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll ---------------------------------------- Weather Bar Assembly Version: 1.0.1439.34951 Win32 Version: 1.0.1439.34951 CodeBase: file:///C:/CMPSC%20115/Weather%20Bar/bin/Weather%20Bar.exe ---------------------------------------- System.Windows.Forms Assembly Version: 1.0.5000.0 Win32 Version: 1.1.4322.573 CodeBase: file:///c:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll ---------------------------------------- System Assembly Version: 1.0.5000.0 Win32 Version: 1.1.4322.573 CodeBase: file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll ---------------------------------------- System.Drawing Assembly Version: 1.0.5000.0 Win32 Version: 1.1.4322.573 CodeBase: file:///c:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll ---------------------------------------- System.Xml Assembly Version: 1.0.5000.0 Win32 Version: 1.1.4322.573 CodeBase: file:///c:/windows/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll ---------------------------------------- Microsoft.VisualBasic Assembly Version: 7.0.5000.0 Win32 Version: 7.10.3052.4 CodeBase: file:///c:/windows/assembly/gac/microsoft.visualbasic/7.0.5000.0__b03f5f7f11d50a3a/microsoft.visualbasic.dll ---------------------------------------- ************** JIT Debugging ************** To enable just in time (JIT) debugging, the config file for this application or machine (machine.config) must have the jitDebugging value set in the system.windows.forms section. The application must also be compiled with debugging enabled. For example: <configuration> <system.windows.forms jitDebugging="true" /> </configuration> When JIT debugging is enabled, any unhandled exception will be sent to the JIT debugger registered on the machine rather than being handled by this dialog. ************************END******************* The code I am using for this is below: Dim wc As New System.Net.WebClient 'Class level variable wc.DownloadFile("http://www.filename.com/file.html", "c:\File\file.html") What is happening? It says it is being used by another process, but it is not. How can I prevent this error? Thanks in advance! Quote
Moderators Robby Posted December 11, 2003 Moderators Posted December 11, 2003 The first thing you can do is handle the exception by placing your code in a Try/Catch block. wc.Dispose() 'once you're done 'and if you're using a StreamReader then close it when you're done... sr.Close() Quote Visit...Bassic Software
R4PM0NK3Y Posted December 11, 2003 Author Posted December 11, 2003 I am only using the code posted above. It does NOT work with OR without wc.Dispose(). Quote
Moderators Robby Posted December 11, 2003 Moderators Posted December 11, 2003 Well looking at the error message it states that access to "current.wbd" is denied. Is the file open? And have placed your code in a Try/Catch block? Quote Visit...Bassic Software
R4PM0NK3Y Posted December 12, 2003 Author Posted December 12, 2003 Well looking at the error message it states that access to "current.wbd" is denied. Is the file open? And have placed your code in a Try/Catch block? After looking over the code, it appears the file was open. After closing the file in the right spot, I still get the error... And what is a Try/Catch block? Quote
R4PM0NK3Y Posted December 15, 2003 Author Posted December 15, 2003 Anybody have any suggestions? :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.