C
Clive Foley
Hey,
using the OpenFileDialog class is causing me errors. Conside the
following code
private void method1()
{
OpenFileDialog open = new OpenFileDialog()
if(open.ShowDialog() == DialogResult.OK)
{
FileStream stream1 = new FileStream(pathName, etc, etc, etc)
//Do some actions
stream1.Close()
method2()
}
}
private void method2()
{
FileStream stream2 = new FileStream(pathName, etc, etc, etc)
//Do some actions
stream2.Close()
}
When i select a file using the OpenFileDialog in method 1 a thread
independant from the main thread becomes visible in the debugger. This
thread has a high priority. Using a Process object i can get to this
thread and it tell me that it's waiting for user input. This thread is
holding all access to the file "pathName" even after it's closed.
Therefore method2 can't open it.I get told when i try to initialize
stream2 that the file "pathName" is already in use. As you can see
though i clearly closed stream1 which was opening the file.
Does anyone know why this happens and what to do about it?
Thanks,
Clive
using the OpenFileDialog class is causing me errors. Conside the
following code
private void method1()
{
OpenFileDialog open = new OpenFileDialog()
if(open.ShowDialog() == DialogResult.OK)
{
FileStream stream1 = new FileStream(pathName, etc, etc, etc)
//Do some actions
stream1.Close()
method2()
}
}
private void method2()
{
FileStream stream2 = new FileStream(pathName, etc, etc, etc)
//Do some actions
stream2.Close()
}
When i select a file using the OpenFileDialog in method 1 a thread
independant from the main thread becomes visible in the debugger. This
thread has a high priority. Using a Process object i can get to this
thread and it tell me that it's waiting for user input. This thread is
holding all access to the file "pathName" even after it's closed.
Therefore method2 can't open it.I get told when i try to initialize
stream2 that the file "pathName" is already in use. As you can see
though i clearly closed stream1 which was opening the file.
Does anyone know why this happens and what to do about it?
Thanks,
Clive