1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
Private Sub LaunchListMediaThread()
NewMediaToList = False
Dim Medias As String = ""
Dim count As Integer = 0
RemplListMediasThread(FilePath, Medias, count)
If Medias.Length > 0 Then Medias = Medias.Remove(0, 1)
MediaTab_Temp = Medias.Split("|")
End Sub
Sub RemplListMediasThread(ByVal RepPere As String, ByRef MediaConcatString As String, ByRef count_avancement As Integer)
Application.DoEvents()
Dim ListOfRep() As String = Directory.GetDirectories(RepPere)
For indexrep = 0 To ListOfRep.Length - 1
RemplListMediasThread(ListOfRep(indexrep), MediaConcatString, count_avancement)
Next
Dim ListOfFiles() As String = System.IO.Directory.GetFileSystemEntries(RepPere, "*.*")
For indexfile = 0 To ListOfFiles.Length - 1
count_avancement += 1
SetLabelText_ThreadSafe(Me.LabelMedia, count_avancement)
SetPBValue_ThreadSafe(Me.MediaProgressBar, count_avancement)
Try
Dim DateCreation As Date = FileDateTime(ListOfFiles(indexfile))
Dim DiffDate As Integer = DateDiff(DateInterval.Minute, DateCreation, Now)
If FileOk(ListOfFiles(indexfile),DiffDate) Then
MediaConcatString = MediaConcatString & "|" & ListOfFiles(indexfile)
AddToMediaTableBackThread(Path.GetFileName(ListOfFiles(indexfile)), "1", DateCreation.ToString("yyyy-MM-dd H:mm:ss"))
End If
Catch ex As Exception
End Try
Application.DoEvents()
Next
End Sub
Sub AddToMediaTableBackThread(ByVal MediaFileName As String, ByVal Statut As String, ByVal DateModif As String)
Dim MySqlString As String = "INSERT INTO " & MysqlPrefixTable & "medias (`media` ,`statut`, `filedate`) VALUES " & " ('" & MediaFileName & _
"', '" & Statut & "', '" & DateModif & "')" & " ON DUPLICATE KEY UPDATE statut='" & Statut & "', filedate='" & DateModif & "';"
Dim MyCommand As New MySqlCommand
Dim MediaMysqlConn As New MySqlConnection
MediaMysqlConn.ConnectionString = MyConnectionString
MyCommand.Connection = MediaMysqlConn
MyCommand.CommandText = MySqlString
Try
MediaMysqlConn.Open()
MyCommand.ExecuteNonQuery()
MediaMysqlConn.Close()
Catch myerror As MySqlException
End Try
MyCommand.Dispose()
End Sub
Delegate Sub SetPBValue_Delegate(ByVal [PB] As ProgressBar, ByVal [value] As Integer)
Private Sub SetPBValue_ThreadSafe(ByVal [PB] As ProgressBar, ByVal [value] As Integer)
Dim pourcent As Integer = 0
pourcent = CInt([value] * 100 / (TotalPrecendent + 2))
If pourcent > 100 Then
pourcent = 100
ElseIf pourcent < 0 Then
pourcent = 0
End If
If [PB].InvokeRequired Then
Dim MyDelegate As New SetPBValue_Delegate(AddressOf SetPBValue_ThreadSafe)
Me.Invoke(MyDelegate, New Object() {[PB], [value]})
Else
[PB].Value = pourcent
End If
End Sub |
Partager