none
Problem with FileSystemWatcher and threads, monothread ? RRS feed

  • Question

  • Hi all,

    I'm using the FileSystemWatcher to perform simple tasks (mainly Print) on newly created files.

    I've noted than it is using thread pool to launch events. the job is done well, but here is the trace I've seen :

    FileSystemWatcher Created thread 5 - file : E:\Dev\SandBox\EventTest\print\labels\PRINT_Y01-X15_000096.jpg
    FileSystemWatcher : PRINT LABEL
    FileSystemWatcher Created thread 4 - file : E:\Dev\SandBox\EventTest\print\labels\PRINT_Y01-X03_001167.jpg
    FileSystemWatcher : PRINT LABEL
    FileSystemWatcher Created thread 4 - file : E:\Dev\SandBox\EventTest\print\labels\PRINT_Y01-X04_000786.jpg
    FileSystemWatcher : PRINT LABEL
    FileSystemWatcher Created thread 4 - file : E:\Dev\SandBox\EventTest\print\labels\PRINT_Y01-X05_001142.jpg
    FileSystemWatcher : PRINT LABEL
    FileSystemWatcher Created thread 4 - file : E:\Dev\SandBox\EventTest\print\labels\PRINT_Y01-X06_001129.jpg
    FileSystemWatcher : PRINT LABEL
    FileSystemWatcher Created thread 4 - file : E:\Dev\SandBox\EventTest\print\labels\PRINT_Y01-X07_001171.jpg
    FileSystemWatcher : PRINT LABEL
    

    It seems that only the first event is using Thread #5, all others events are using thread #4, this is the reason why I think this watcher is mono-thread only...

    I'm out of solutions since I need to parallelize printing (at least 4 in //) but I don't know how to :

    1/ Raise the number of thread the watcher can use (ThreadPool.GetMaxThread gives me 32767)

    2/ Make it really multi-thread

    3/ use another solution... but which one.

    Does anyone can help me ?

    Thank in advance

    Cyril

    Friday, June 14, 2019 4:17 PM

All replies

  • Hi,

    You'd better provide your code and explain your issue in detail.

     Dim watcher As FileSystemWatcher = New FileSystemWatcher()
    
            watcher.Path = "D:\"
            AddHandler watcher.Created, Sub(ByVal source As Object, ByVal e2 As FileSystemEventArgs)
    
                                            ThreadPool.QueueUserWorkItem(New WaitCallback(Sub()
    
                                                                                          End Sub))
                                        End Sub
            watcher.EnableRaisingEvents = True

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 17, 2019 5:23 AM