Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27189

simple filewatcher questions

$
0
0
Hi
reading up on filewatcher and how to set it up and every examplei come accross seems to be doing it differently, im just wandering why.

im pressuming the msdn example is doing what it usually does and has it setup in maybe the best and most likely the complicated way.
the msdn example is calling the class directly without instantiating and is also using shared subs? its also using permission headers/decorations
i couldnt really test it because it was written for the console and i converted it to a form app and got errors, something like 'cannot call this sub without instantiating the class first"

another example didnt use the header/decorations for declaring full permission(i havent looked into these headers yet) and also didnt instantiate a class it directly used the class, but this also had an error when i set it up almost in the same way as the msdn example, but this error was threading error, trying to change control properties from another thread. which was strange sincei didnt setup another thread to run. i tried to setup another sub to handle the text change to the control but then got another error. i left that at that.

and this last example i found is doing it in a way which i would think is more normal, its instantiating the class, using withevents clause, and everything looks normal except one thing.

the code in red i just dont get, watchdir.notifyfilter is set to = 0 and then its set to = itself or a filename, whats happening there
Code:

Private m_WatchDirectory As String
Private WithEvents m_FileSystemWatcher As FileSystemWatcher

Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    lstFiles.Items.Add(Now.ToString() & " Starting")

    ' Get the path to the directory we will watch.
    m_WatchDirectory = Application.StartupPath
    m_WatchDirectory = m_WatchDirectory.Substring(0, _
        m_WatchDirectory.LastIndexOf("\"))
    m_WatchDirectory &= "\Files"

    ' Make the FileSystemWatcher.
    m_FileSystemWatcher = New _
        FileSystemWatcher(m_WatchDirectory, "*.txt")
    m_FileSystemWatcher.NotifyFilter = 0
    m_FileSystemWatcher.NotifyFilter = _
        m_FileSystemWatcher.NotifyFilter Or _
        NotifyFilters.FileName
    m_FileSystemWatcher.EnableRaisingEvents = True

    ' Process any files that already exist.
    ProcessExistingFiles(m_WatchDirectory)
End Sub

does it matter which way im going to do this or will each way perform differently?

Viewing all articles
Browse latest Browse all 27189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>