Hi,
ich hab mir mit Hilfe von [VB 2008] MultipleFileSystemWatcher eine Klasse MultipleFileSystemWatcher gebastelt:
In meinem Hauptcode sieht es dann so aus:
Aber solange ich in dieser Sub bin sind alle lokalen Variablen leer. Wenn ich da nach das z.B. mit einem Button teste steht wieder was drinne.
Wo ist der Fehler?
ich hab mir mit Hilfe von [VB 2008] MultipleFileSystemWatcher eine Klasse MultipleFileSystemWatcher gebastelt:
VB.NET-Quellcode
- Imports System.IO
- Imports System.ComponentModel
- Public Class MultipleFileSystemWatcher
- Public Event Created As EventHandler(Of FileSystemEventArgs)
- Private lWatcher As List(Of FileSystemWatcher)
- Public Sub New()
- lWatcher = New List(Of FileSystemWatcher)
- End Sub
- Public Sub New(ByVal Paths() As String)
- Me.New()
- For Each Path As String In Paths
- Me.AddPath(Path)
- Next
- End Sub
- Public Sub New(ByVal Paths() As String, ByVal Pattern As String)
- Me.New()
- For Each Path As String In Paths
- Me.AddPath(Path, Pattern)
- Next
- End Sub
- Public Sub AddPath(ByVal Path As String)
- Me.AddPath(Path, "*.*")
- End Sub
- Public Sub AddPath(ByVal Path As String, ByVal Pattern As String)
- lWatcher.Add(NewWatcher(Path, Pattern))
- End Sub
- Public Sub RemovePath(ByVal Path As String)
- For Each fsw As FileSystemWatcher In lWatcher
- If fsw.Path = Path Then
- lWatcher.Remove(fsw)
- End If
- Next
- End Sub
- Public Sub RemoveAll()
- lWatcher.Clear()
- End Sub
- Private Function NewWatcher(ByVal Path As String, ByVal Pattern As String) As FileSystemWatcher
- Dim fsw As New FileSystemWatcher(Path, Pattern)
- AddHandler fsw.Created, AddressOf fswCreated
- fsw.EnableRaisingEvents = True
- Return fsw
- End Function
- Private Sub fswCreated(ByVal sender As Object, ByVal e As FileSystemEventArgs)
- OnEvent(sender, e, CreatedEvent)
- End Sub
- Private Sub OnEvent(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs, ByVal [event] As System.Delegate)
- Form1.mfsw_ausgelöst(e.FullPath)
- End Sub
- End Class
In meinem Hauptcode sieht es dann so aus:
VB.NET-Quellcode
- Private WithEvents mfsw As New MultipleFileSystemWatcher
- Dim alle_von As New List(Of String)
- Dim alle_nach As New List(Of String)
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- alle_von.Add("test")
- alle_nach.Add("test2")
- End Sub
- Public Sub mfsw_ausgelöst(ByVal pfad As String)
- MsgBox(alle_von(0))
- End Sub
Aber solange ich in dieser Sub bin sind alle lokalen Variablen leer. Wenn ich da nach das z.B. mit einem Button teste steht wieder was drinne.
Wo ist der Fehler?