我最近測試了一些FileSystemWatcher
,並想知道.NET中的事件處理是如何工作的。例如,與此代碼在VB.NET:在.NET上使用相同函數處理多個事件
Dim fsw1, fsw2, fsw3 As New FileSystemWatcher()
Private Sub fsw_Error(sender As Object, e As ErrorEventArgs) _
Handles fsw1.Error, fsw2.Error, fsw3.Error
Dim iCont As Integer = 1
Dim fsw As FileSystemWatcher = CType(sender, FileSystemWatcher)
While Not fsw.EnableRaisingEvents AndAlso iCont < 120
iCont += 1
Try
fsw.EnableRaisingEvents = True
txtResultado.Clear()
Catch
fsw.EnableRaisingEvents = False
Threading.Thread.Sleep(30000)
End Try
End While
End Sub
每次上執行任何FileSystemWatcher
S上的函數的發生錯誤。爲每個FileSystemWatcher
生成一個不同的函數線程?它們可以在同時執行多個進程時互相干擾嗎?
C#和VB.NET在這裏可能有區別嗎?
我沒有在這裏看到任何線程或多個FileSystemWatchers - 所以我不知道你在說什麼... – 2013-02-13 09:05:19
@DanielHilgarth FileSystemWatchers是fsw1,fsw2和fsw3。爲什麼downvotes?這個問題是關於與事件相同功能的多次執行。代碼就是一個例子。 – SysDragon 2013-02-13 09:14:40
'Dim fsw1,fsw2,fsw3由於新的FileSystemWatcher()'是多個FileSystemWatchers,@Daniel Hilgarth;如果我遵循,多個線程將是那些@SysDragon感覺可能與多個FileSystemWatchers引發的事件有關的線程。 – J0e3gan 2013-02-13 09:17:05