Click here to Skip to main content
15,890,438 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: How to find out if a file is in use before reading the data in that file Pin
Dave Kreskowiak13-Nov-12 8:09
mveDave Kreskowiak13-Nov-12 8:09 
GeneralRe: How to find out if a file is in use before reading the data in that file Pin
KreativeKai13-Nov-12 8:22
professionalKreativeKai13-Nov-12 8:22 
GeneralRe: How to find out if a file is in use before reading the data in that file Pin
KreativeKai13-Nov-12 8:46
professionalKreativeKai13-Nov-12 8:46 
AnswerRe: How to find out if a file is in use before reading the data in that file Pin
KreativeKai13-Nov-12 8:13
professionalKreativeKai13-Nov-12 8:13 
GeneralRe: How to find out if a file is in use before reading the data in that file Pin
Dave Kreskowiak13-Nov-12 9:57
mveDave Kreskowiak13-Nov-12 9:57 
AnswerRe: How to find out if a file is in use before reading the data in that file Pin
Eddy Vluggen13-Nov-12 11:41
professionalEddy Vluggen13-Nov-12 11:41 
GeneralRe: How to find out if a file is in use before reading the data in that file Pin
KreativeKai14-Nov-12 1:37
professionalKreativeKai14-Nov-12 1:37 
GeneralRe: How to find out if a file is in use before reading the data in that file Pin
_Vitor Garcia_19-Nov-12 1:12
_Vitor Garcia_19-Nov-12 1:12 
I had a similar problem and solved it using


VB
Public Function FileInUse(ByVal sFile As String) As Boolean
        If System.IO.File.Exists(sFile) Then
            Try
                Dim F As Short = FreeFile()
                FileOpen(F, sFile, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite)
                FileClose(F)
            Catch
                Return True
            End Try
        End If
    End Function



usage

    Do While FileInUse(sSourcePath & "\" & sFileName & "." & sExtension)
            System.Threading.Thread.Sleep(1000)

            sTimeOut += 1

            If sTimeOut = 15 Then
        WriteLogLog("File " & sFile & " in use.")
                Exit Sub
            End If

        Loop


Im testing each second if the file can be opened, if it can't then it is because it is in use. When the loop ends I know my file is no longer in use.
best regards

modified 19-Nov-12 10:20am.

QuestionVB Script for automatically turning off the monitor Pin
Prasan Cumar13-Nov-12 4:14
Prasan Cumar13-Nov-12 4:14 
AnswerRe: VB Script for automatically turning off the monitor Pin
Dave Kreskowiak13-Nov-12 4:59
mveDave Kreskowiak13-Nov-12 4:59 
AnswerRe: VB Script for automatically turning off the monitor Pin
Bernhard Hiller13-Nov-12 21:20
Bernhard Hiller13-Nov-12 21:20 
QuestionSQL Configuration Pin
DinoRondelly13-Nov-12 3:46
DinoRondelly13-Nov-12 3:46 
AnswerRe: SQL Configuration Pin
David Mujica13-Nov-12 4:07
David Mujica13-Nov-12 4:07 
GeneralRe: SQL Configuration Pin
DinoRondelly13-Nov-12 5:56
DinoRondelly13-Nov-12 5:56 
GeneralRe: SQL Configuration Pin
David Mujica13-Nov-12 9:44
David Mujica13-Nov-12 9:44 
GeneralRe: SQL Configuration Pin
DinoRondelly13-Nov-12 18:17
DinoRondelly13-Nov-12 18:17 
QuestionSource Code Pin
tesraghavan12-Nov-12 15:59
tesraghavan12-Nov-12 15:59 
AnswerRe: Source Code Pin
Dave Kreskowiak13-Nov-12 2:20
mveDave Kreskowiak13-Nov-12 2:20 
QuestionMonitoring Network Usage For Remote Users Pin
DinoRondelly12-Nov-12 10:54
DinoRondelly12-Nov-12 10:54 
AnswerRe: Monitoring Network Usage For Remote Users Pin
Eddy Vluggen13-Nov-12 11:44
professionalEddy Vluggen13-Nov-12 11:44 
QuestionScan Multipage Tiff Image For A Barcode Pin
daveofgv12-Nov-12 4:07
daveofgv12-Nov-12 4:07 
AnswerRe: Scan Multipage Tiff Image For A Barcode Pin
Eddy Vluggen12-Nov-12 10:54
professionalEddy Vluggen12-Nov-12 10:54 
QuestionGetting All Logged On Users and IP VB.net Pin
DinoRondelly12-Nov-12 3:39
DinoRondelly12-Nov-12 3:39 
AnswerRe: Getting All Logged On Users and IP VB.net Pin
Dave Kreskowiak12-Nov-12 4:37
mveDave Kreskowiak12-Nov-12 4:37 
GeneralRe: Getting All Logged On Users and IP VB.net Pin
DinoRondelly12-Nov-12 4:44
DinoRondelly12-Nov-12 4:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.