Find file, not found? wait x seconds and try again

G

Guest

I have a function that converts a file to another formait. But sometimes it
might take up to 50-100 milliseconds before the file exists on the location
the folder is looking for.

I want something like

if file.exists(filename) then
convert(filename)
else
wait(100)
If file.exists(file) then
convert(filename)
end if

is there a wait function in vb.net?

I want to call the wait in a windows form application and not in the DLL
that reads the file and converts it....
 
G

Guest

I expect the file to exist, only 1 in the 10000 times I run the function the
file is created a few milliseconds later. Using filesystemwatcher would only
be useful if the file is always created after the function is started.
 
A

Andrew Morton

Philip said:
is there a wait function in vb.net?

I want to call the wait in a windows form application and not in the
DLL that reads the file and converts it....

Are you looking for System.Threading.Thread.Sleep?

Andrew
 
P

Phill. W

Philip Wagenaar said:
I have a function that converts a file to another formait. But sometimes
it might take up to 50-100 milliseconds before the file exists on the
location the folder is looking for.
I want something like

if file.exists(filename) then
convert(filename)
else
wait(100)
If file.exists(file) then
convert(filename)
end if

How is your Convert function working? I /assume/ it's running
some external process and it's this that isn't finishing "quickly"
enough.
Of so, look at the WaitForExit method on the Process class.

HTH,
Phill W.
 
G

Guest

I have a function that takes an xmldocument as parameter and returns the same
xmldocument.


The function does:
In the xmldocument I look for a filename. If I find a filename and it exits
on disk I replace the name of the file with it's contents encoded in mime
format. The function that does the mimeencoding is in the same class.

Problem is that the xml file and the file I covert to mime are copied into a
directory which triggers all of this. But sometimes the function for
converting the filename to its content in mime encoding is ran so quicky, it
is ran when the xml doucment is copied to the directory, but the copying of
the other file is not finished yet
 
H

Herfried K. Wagner [MVP]

Philip Wagenaar said:
its not running in a thread.
[...]
Are you looking for System.Threading.Thread.Sleep?

Sure, it's running in the application's main thread. Thus you can use
'Thread.Sleep(1000)' to block the thread for one second, for example.
 
A

Andrew Morton

Philip said:
its not running in a thread.

Not even in the CurrentThread?

I could be wrong, but surely everything runs in a thread, including your
program?

Andrew
 
J

Jay B. Harlow [MVP - Outlook]

Philip,
| its not running in a thread.
Actually it is! As all code in .NET runs in a thread. If you don't create a
thread then its running in the thread that the OS created when it created
your process.

Thread.Sleep is a shared method, it works on the current thread.

--
Hope this helps
Jay [MVP - Outlook]
T.S. Bradley - http://www.tsbradley.net


| its not running in a thread.
|
| "Andrew Morton" wrote:
|
| > Philip Wagenaar wrote:
| > > is there a wait function in vb.net?
| > >
| > > I want to call the wait in a windows form application and not in the
| > > DLL that reads the file and converts it....
| >
| > Are you looking for System.Threading.Thread.Sleep?
| >
| > Andrew
| >
| >
| >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top