코드를 정리하기 위해 일부 코드를 일부 클래스 파일로 옮기려고합니다. 문제가있는 한 가지 영역은 작업을 수행하는 개체와 진행률 표시 줄 사이의 이벤트 진행 상태를보고하는 것입니다.다른 클래스의 이벤트 처리
이벤트 함수를 새 클래스에 배치해야하지만 호출 폼의 진행률 막대를 업데이트해야한다고 생각하십니까? 클래스 \ 객체가 이벤트 처리기 대신에 업데이트를 반환 할 수 있습니까?
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
를 통해 사용 :
현재 형태는 모든 코드가
DoRestore(SQLServer, "C:\SQLBACKUP.bak", DatabaseName)
이 코드를 사용하면 매우 심각한 문제가 발생할 것입니다. 이 답변을 확인하십시오 : http://stackoverflow.com/questions/5181777/c-application-doevents/5183623#5183623 –