I have some issues related to WebBrowser Control in .net cf.
And in its URL Property I am assigning one .htm file. In that .htm file we are setting the backgroung using one image file
"#BKGROUND#"
, "\"" + FilePaths.stStrImagesFolderPath + @"\backgroundImage.jpg" + "\""But sometimes, specially while doing fast navigation , Its throwing exception "The process can not access the file because it is being used by another process." Sometimes its coming for .htm file and sometimes it comes for backgroundImage.jpg file.
How to avoid this.
Kindly help.

The process can not access the file because it is being used by another process.
Argenta
Ken Cooper
Subhasmita,
I've got a couple more questions:
In the meantime, I'll try to find out if the native controls lock any files during navigation.
Thanks
Dan
Moridi
A few questions:
Thanks
Dan
poker_paul
Hey Dan,
1. The target platform is WM5
2. We r using .Net cf 2.0.
3. No its not reproducable on Emulator.
4. Yeah we are using the same Web-Browser control on each tab. Just Changing the WeBrowser.Url propery as the tab changes.
5. Yeah OnClicking the Tab for the first time, we are creating and saving the corresponding .html file and setting it as the Url of the WebBrower.
Note : html file used is different for all the tabs, but the backgroundImage file for all the .html file are tha same.
And one more thing at some point of time we are deleting the .html files also. So at that point of time also this exception can come right.
Thanks for your response buddy. Can you suggest me any logic to avoid this kind of exception Sowhere I have read about trying to open the file with fileShare 'None', I was planning to put some delay if exception occurs...But What I know how long it will take to release the file......
And one more thing can we forcibly close any file which is being used by some other process
lord_8
I would suggest a couple of things:
- Both before and after you navigate to a page, attempt to open and read the file with System.IO.FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read). This will determine whether or not the WebBrowser has the file locked.
- When navigating to a new tab, don't set WebBrowser.Url until you are sure that the current tab has finished it's file operations.
- Monitor the Navigating, Navigated, and DocumentComplete events to see at which point the exception is raised. I'm not sure how helpful this will be, but it might point to whether it is your file or a cached file that is locked.
- Put the call that is throwing the exception in a try/catch block in loop and retry until the navigation succeeds
Let me know what you find out.bool keepTrying = true;while (keepTrying)
{
try
{
webBrowser1.Url = new Uri("myfile");
}
catch (Exception x)
{
keepTrying = DetermineWhetherToKeepTrying();
}
}
Dan
Sniper167
Hey Thank you so much Dan. I am implementing this and I will let you know, the results.
Regards,
Subhasmita.