Hi I’m Having some trouble, i was wonder how to read an XML file in a new thread heres basically what I’m trying to do:
//This is ran when the user presses the Enter Key
Thread LoadThread = new Thread(new ThreadStart(Test));
LoadThread.Start();
private static void Test()
{
FileStream stream = File.Open("TEST_1.xml", FileMode.Open);
//----
// Code Using File (I know this stuff works)
//----
stream.Close();
}
Here’s the Error.
Directory\TEST_1.xml’ because it is being used by another process.
But when its not a thread of its own it works fine ?
Thanks for the help, if this can’t be done like this, how can i open the file without it making my program Freeze until the file has been opened ?
thanks again.
I took your sample code and did not run into any problems. I did, however, get the same exception when I pressed the enter key while the file was being read. (i.e. pressed the enter key twice) Is it possible you have two handlers for the Enter key, which are both triggering this file to be opened. Can you place a breakpoint on the File.Open statement and see how many times it is hit before the exception occurs.