OpenFileDialog error - help please!!!!

  • Thread starter Thread starter Sailor Foley
  • Start date Start date
S

Sailor 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 stream = new FileStream(pathName, etc, etc, etc)
//Do some actions
stream.Close()
method2()
}
}

private void method2()
{
FileStream stream = new FileStream(pathName, etc, etc, etc)
//Do some actions
stream.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.

Does anyone know why this happens and what to do about it as im unable
to abort this thread or kill it?

Thanks,
Clive
 
Sailor,

Well it is hard to tell exactly what is going on here since you do not
provide the error which you are getting, nor source code which can be
executed localy to reproduce the problem. However I will try to shot
some ideas your way.

(1) The variable pathName, where is it declared? Do have you
declared it earlier in your class and ensured that is does have the
correct scope?

(2) One more thing about pathName, you do nerver assign it anything
in the code you provided. I would have thought you would use the
OpenFileDialog to fetch & store the path in the pathName variable?

(3) If you have not declared pathName to have class scrope, then you
might want to consider changing the signature of method2() to accept
a string (the path) like method2(string path) and call then call it from
method1() with method2(pathName).

The OpenFileDialog nor the FileStream is holding a lock on the file
specified
by the pathName variable, so this will not be the source of your problems.

HTH,

//Andreas
 
Hi Sailor,

From what I gather, ur OpenFileDialog is working fine, and the issue is
probably in the '//Do some action' code section. Could you please post
that too?

Regards,
fbhcah
 
hey,

the line //Do some action is bogus. This mysterious Thread occurse
right after the line to check if the DialogResult is Ok. If i put
nothing into the If block the thread still occurs. It's all very weird
to me.
 
Back
Top