最近、いくつかFileSystemWatcher
の をテストしていて、イベント処理が .NET でどのように機能するのか疑問に思っています。たとえば、VB.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
、関数が実行されます。FileSystemWatcher
?ごとに関数の異なるスレッドが生成されます。同時に複数を実行しているときに、互いに干渉することはできますか?
これには、C# と VB.NET の違いがあるのではないでしょうか?