I'm trying to move some code into some class files to clean up my code. One area I'm having trouble with is reporting progress for events between the object performing the task and a progress bar.
I guess the event functions have to be placed in the new class but they also need to update the progress bar on the calling form? Can the class\object return updates in place of the event handlers?
Currently the form has all the code:
Function DoRestore(ByVal SQLServer As String, ByVal BackupFilePath As String, ByVal DatabaseName As String)
Dim Server As Server = New Server(SQLServer)
Server.ConnectionContext.ApplicationName = Application.ProductName
Dim res As Restore = New Restore()
Dim dt As DataTable
res.Devices.AddDevice(BackupFilePath, DeviceType.File)
dt = res.ReadFileList(Server)
res.Database = DatabaseName
res.PercentCompleteNotification = 1
AddHandler res.PercentComplete, AddressOf RestoreProgressEventHandler
AddHandler res.Complete, AddressOf RestoreCompleteEventHandler
res.SqlRestoreAsync(Server)
While res.AsyncStatus.ExecutionStatus = ExecutionStatus.InProgress
Application.DoEvents()
End While
End Function
Private Function RestoreProgressEventHandler(ByVal sender As Object, ByVal e As PercentCompleteEventArgs)
'Update progress bar (e.Percent)
End Function
Private Sub RestoreCompleteEventHandler(ByVal sender As Object, ByVal e As Microsoft.SqlServer.Management.Common.ServerMessageEventArgs)
'Signal completion
End Sub
Used via:
DoRestore(SQLServer, "C:\SQLBACKUP.bak", DatabaseName)