# vb.net waiting for a file to finish growing



## shuggans (Jan 22, 2012)

This is a quick post to demonstrate how to get your program to wait to perform any actions on a file until its file size has finished growing.
I spent alot of time figuring this out and getting it to work how I liked it to, and while simple there is a single method I missed that made it all work:


```
FileInfo.Refresh()
```

Note that you will want to do this on a separate thread other than the main thread, or the UI will hang.
Here is a working example:


```
'create 2 long integers, set the total file size to 5, the new file size to 0.  We will use these to update our program on the size of the file in a loop.
        Dim FileTotalSize As Long = 5
        Dim FileNewSize As Long = 0
        Dim FileInfo As New FileInfo(FileInQuestion)
       'create our loop
 Do
           'sleep thread for 5 seconds while we give the file a chance to grow
           Thread.Sleep(5000)
           'refresh our FileInfo variable to update actual current size
            FileInfo.Refresh()
           'Record the actual current size to our TotalSize variable
            FileTotalSize = FileInfo.Length()
            'sleep thread for 5 seconds while we give the file a chance to grow
            Thread.Sleep(5000)
           'refresh our FileInfo variable to update actual current size
            FileInfo.Refresh()
           'Record the actual current size to our NewTotalSize variable
            FileNewSize = FileInfo.Length
           'If both variables are equal to eachother, it is safe to say the file is 
           'done growing. We also continue the loop if either variable is = 0,
           'indicating the file hasn't yet started growing.
 Loop Until FileNewSize = FileTotalSize And FileNewSize <> 0 And FileTotalSize <> 0
        '--------Perform actions on file below-------------
```

There you have it,
Happy coding TPU


----------

