例如,在你问答I/O的问题之后,我最近(或所有年份的100次)写了一幅同步的档案扫描仪。 它像你所希望的那样,通过在事件中立即出现新的事例和hoo。
我将这一功能提升到能够实施跨阅读安全的班级。 班级冲撞事件,向打电话者通报最新情况和填写情况。
你们说,“来源法必须依次结合实施该守则的顺序来解读”,但认识到,表面上是相互平行的。 因此,它愿意将守则结构分开。
这表明,可再使用的法典被单独分类......
Public Class FileScanner
Public Event Scan_Complete(sender As Object)
Public Event Scan_Update(sender As Object, filename As String)
Public Event Scan_Error(sender As Object, ex As Exception)
Private Delegate Sub del_ScanComplete()
Sub New(syncObject As Control, path String)
Me.SynchronizeObject = syncObject
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf ScanFilesAsync), path)
End Sub
Private Sub ScanFilesAsync(ByVal state As Object)
scan files here
call the method to raise the Complete event
ScanComplete()
End Sub
Private Sub ScanComplete()
If SynchronizeObject.InvokeRequired Then
we cant raise event on a different thread than our caller
so lets invoke our method on the same caller thread
Dim d As New del_ScanComplete(AddressOf ScanComplete)
SynchronizeObject.Invoke(d)
Else
no synchronize needed, tell the caller we are done
RaiseEvent Complete(Me)
End If
End Sub
End Class