Question

I have a folder being watched for new file creations. When a file is created the task that is run can take 5-30 min. Often a new file can be created when the last one is still being processed.

From a few test cases it seems that there is some sort of queue for the tasks. Is there a way to allow the tasks to be run simultaneously? If not is there a way to see the queue or be notified when something is put into the queue?

    $folder = 'C:\Users\Public\Recorded TV' # Enter the root path you want to monitor.
    $filter = '*.*'  # You can enter a wildcard filter here.

    $fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}

    Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action
    { <do stuff> }
Was it helpful?

Solution

If you want to do things simultaneously you would want to have the action start a job to run in the background, but then you may need a system to track jobs. If you don't mine letting things just filter through the event queue you can leave it as it is and just monitor things with Get-Event.

More info on either of these can be found online or in powershell with get-help about_jobs or get-help get-event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top