Open file dialog error

  • Thread starter Thread starter Clive Foley
  • Start date Start date
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
 
Clive,

Please do not post the same question using two different subject and
two different names in less than one hour. People will help you if and
when they can. Remember that many of the list participants might be in
a different timezone than you.

Also, there are a few things you can do to help speed up replies to your
threads, and they are:

(1) State a clear question.
(2) Include the error/exception which you are getting, if any.
(3) Provide source code which recreates the problem
(4) Provided source code should be able to be run on the
readers computer, that is please inform if you are using any
thirdparty components and see to is that the code you provide
can be compiled in the state is it shared.
(5) Do not cross or multipost, this will only annoy people and
may have them skip your question in favour of someone elses.

HTH,

//Andreas
 
Hey,

i tried to dispose the filestream but when stepping through the code
with the debugger i can see that the filestream object does get disposed
but this thread is still active. It can't be swapped over to as im told
there is no source code available.

Has anyone ever experienced this or know what may cause threads to be
implicitly created like this.

Cheers,
Clive
 
Back
Top