Hi Jmc, after I posted it I realize that the files that are downloading should not be added to the list at all. But the user may modify some file while he is downloading from the server so the problem will be there.
Now the code is big so I will post some sections of it. If you want to see some sections of it then let me know.
Edit* Oh almost forget! The ProgressBar’s Style property is set to Marquee so I am not setting any property of it.
I call it lilek this
vb Code:
Me.downloadFilesWorker.RunWorkerAsync(arg)
the "arg" is just an object that contains the file names to be downloaded.
This is the backgroudworker events:
vb Code:
Private Sub downloadFilesWorker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles downloadFilesWorker.DoWork
Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
Me.ServerDownloadFiles(worker, e)
End Sub
Private Sub downloadFilesWorker_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles downloadFilesWorker.ProgressChanged
Me.FilesRemainNumStatusLabel.Text = CStr(e.ProgressPercentage)
End Sub
Private Sub downloadFilesWorker_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles downloadFilesWorker.RunWorkerCompleted
Me.StatusProgressBar.Visible = False
Me.FilesRemainStatusLabel.Visible = False
Me.FilesRemainNumStatusLabel.Visible = False
Me.ClientUploadFilesButton.Enabled = True
Me.ServerDownloadButton.Enabled = True
Me.ServerDeleteMenuItem.Enabled = True
Me.ServerCancelButton.Enabled = False
Me.StatusLabel.Text = Me.client.State.ToString
If e.Error IsNot Nothing Then
MessageBox.Show(e.Error.Message, "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf e.Cancelled Then
MessageBox.Show("The process has been cancelled!", _
"Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf CInt(e.Result) = 0 Then
MessageBox.Show("File restore completed successfully!", _
"Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf CInt(e.Result) > 0 Then
MessageBox.Show("File restore was unsuccessful!" & Environment.NewLine _
& CInt(e.Result) & " file(s) did not restore successfully.", _
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
If Me.ClosingPending Then
Application.Exit()
End If
End Sub
and this is the fileSystemWathcher event
vb Code:
Private Sub ClientFileSystemWatcher_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles ClientFileSystemWatcher.Created
Dim dInfo As New IO.DirectoryInfo(e.FullPath)
Dim fInfo As New IO.FileInfo(e.FullPath)
If dInfo.Exists Then
Dim tvNode As TreeNode
If My.Settings.CheckedFolders.Contains(dInfo.Parent.FullName) Then
My.Settings.CheckedFolders.Add(e.FullPath)
End If
tvNode = Node.GetNode(Me.ClientTreeView.Nodes, dInfo.Parent.FullName)
If tvNode IsNot Nothing AndAlso Not tvNode.FirstNode.Text = String.Empty Then
tvNode.Nodes.Add(e.FullPath, dInfo.Name).Checked = tvNode.Checked
End If
ElseIf fInfo.Exists Then
If My.Settings.CheckedFolders.Contains(fInfo.DirectoryName) Then
If Not My.Settings.CheckedFiles.Contains(e.FullPath) Then
My.Settings.CheckedFiles.Add(e.FullPath)
My.Settings.ModifiedFiles.Add(e.FullPath)
End If
End If
End If
If Me.ClientTreeView.SelectedNode IsNot Nothing Then
Me.ClientLoadListView(Me.ClientTreeView.SelectedNode.Name)
End If
Me.BackupFilesNumStatusLabel.Text = CStr(My.Settings.ModifiedFiles.Count)
Me.ClientTotalNumStatusLabel.Text = CStr(My.Settings.CheckedFiles.Count)
End Sub