Jump to content

Network Monitoring is sluggish / non-responsive


 Share

Recommended Posts

Hi guys, I'm just using _WinAPI_ReadDirectoryChanges to monitor a network folder.. but the buffer size seems to be creating some issues where the script is slow / non-responsive a lot of the time. I BELIEVE it's attributed to the buffer size anyways. From the help file, and experience, buffer size must be LESS then 64k but buffer size being less then 64k seems to also be the cause as mentioned in the help file..? Ideas? So Damned if you do, damned if you don't? 

Quote from them help file:

To prevent the crash of the script, use the buffer at least not less than 64 KB.
If the buffer is greater than 64 KB and the application is monitoring a directory over the network, the function fails.
This is due to a packet size limitation with the underlying file sharing protocols.

 

#include <APIFilesConstants.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIError.au3>
#include <WinAPIFiles.au3>
#include <WinAPIMem.au3>

Global $g_sPath = "\\server\LIMS\Data Import\CO"

Local $hDirectory = _WinAPI_CreateFileEx($g_sPath, $OPEN_EXISTING, $FILE_LIST_DIRECTORY, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE), $FILE_FLAG_BACKUP_SEMANTICS)
If @error Then
;~  MsgBox(0,0,0)
    _WinAPI_ShowLastError('', 1)
EndIf

Local $pBuffer = _WinAPI_CreateBuffer(64000)

Local $aData
While 1
    $aData = _WinAPI_ReadDirectoryChanges($hDirectory, $FILE_NOTIFY_CHANGE_CREATION, $pBuffer, 64000, 1)
    If Not @error Then
        _ArrayDisplay($aData, '_WinAPI_ReadDirectoryChanges')
    Else
        MsgBox(0,0,0)
        _WinAPI_ShowLastError('', 1)
    EndIf
WEnd

image.png.10744bb8fe0008005bc123c02ac4797f.png

Edited by BatMan22
Link to comment
Share on other sites

I would be tempted to try an asynchronous approach using this function in overlapped mode.  I vaguely remember someone testing it and affirming it was more robust over a network.  But I could be wrong, so you will need to test it in your environment.  On the other hand, since it is non-blocking, it might be easier for the function to return normally if the directory failed to be read.

Link to comment
Share on other sites

@Nine And.. you lost me. You're talking about a function that does not currently exist in autoit, am I correct? "_WinAPI_ReadDirectoryChangesW" is not a function, so is that something I would need to add to my WinAPIFiles.au3 include?

FindBatch()

Func FindBatch()
    Local $hDirectory = _WinAPI_CreateFileEx($PlateLayoutLocations, $OPEN_EXISTING, $FILE_LIST_DIRECTORY, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE), $FILE_FLAG_BACKUP_SEMANTICS)
    If @error Then
        _WinAPI_ShowLastError('', 1)
    EndIf

    Local $pBuffer = _WinAPI_CreateBuffer(64000)

    Local $aData
    While 1
        $aData = _WinAPI_ReadDirectoryChanges($hDirectory, $FILE_NOTIFY_CHANGE_CREATION, $pBuffer, 64000, 1)
        If Not @error Then
            If StringInStr($aData[1][0], "LunaMultiplex Plate Layout_") Then
                ConsoleWrite(@CR & "New Plate Layout Found! " & $aData[1][0] & @CR)
                WinWait("Microsoft Access", "To CV Layout done.")
                WinActivate("Microsoft Access", "To CV Layout done.")
                Send("{Enter}")
                $c = MsgBox(4, 0, "YES OR NO?")
                If $c = 6 Then
                    $PlateName = $aData[1][0]
                    $batchID = StringTrimLeft($aData[1][0], 27)
                    $batchID = StringTrimRight($batchID, 4)
                    ConsoleWrite($batchID)
                    PrepPate()
                EndIf
            EndIf
        Else
            _WinAPI_ShowLastError('', 1)
        EndIf
    WEnd
EndFunc   ;==>FindBatch

 

 

Link to comment
Share on other sites

51 minutes ago, BatMan22 said:

You're talking about a function that does not currently exist in autoit, am I correct?

True.  It is more complex than the one you are using but I think it is worth a try.  Search the forum, I remember someone posting a working example of it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...