Jump to content

Recommended Posts

Posted

Reading the documentation for a function, I found this line:
"The _WinAPI_ReadDirectoryChanges() function works only in synchronous mode."

What exactly is considered synchronous and asynchronous modes for AutoIt? I've tried to google it and search the forums, but the words are never brought up. 

Does anyone have a place I can learn more of this mode?

Thanks. 

Posted
Just now, junkew said:

So synchronous and asynchronous apply to autoit as it would any language?

So would AutoIt always be synchronous? Or is there some other deciding factor here?

1 minute ago, Jos said:

you are sure you read my posts in that specific thread?

... And why not ask it there?

Jos

I felt it was a fundamentally different thread, where he was asking for help. You also seemed done with that specific thread.

  • Developers
Posted (edited)
13 minutes ago, Zein said:

I felt it was a fundamentally different thread, where he was asking for help.

Not really as I've mentioned it there in relation to the issue posted, but the OP seems to be totally ignoring it, hence my last comment.

13 minutes ago, Zein said:

You also seemed done with that specific thread.

So yes, but merely with the OP, not when somebody shows effort and has a valid question. ;)

Jos 

EDIT: I do have the working version of that script, as proposed, ready when that OP is up to speed as to why things don't work. 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted
4 hours ago, junkew said:

Read multithreading in faq.

See register callback in helpfile

So in general AutoIt is synchronous calls of functions.

Thank you, I was unaware of any multithreading in AutoIT.
 

17 hours ago, Jos said:

Not really as I've mentioned it there in relation to the issue posted, but the OP seems to be totally ignoring it, hence my last comment.

So yes, but merely with the OP, not when somebody shows effort and has a valid question. ;)

Jos 

EDIT: I do have the working version of that script, as proposed, ready when that OP is up to speed as to why things don't work. 

Oh that makes sense, sorry for the bad assumption I made :(. I plan on using the function call on a lab computer so that I can make a really roundabout/simplistic "remote shell" like program. It should be running at all times like a service, but I can't entirely figure out how to make the script exit if I ever need it to without committing another change to the directory.

 

Posted

There is a way to run that WinAPI function asynchronously, but I think it's way over the head of the poster in that thread. It's over mine I know.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

@Jos

I'm working with the little code snippet you provided in the other thread as a base, and I'm curious about behavior.

Why does a single file change (heck, I only change 1 letter in a text file then save) cause 2 iterations of the while loop?
I thought that ReadDirectoryChanges would block until the next file change, but it seems to return twice back to back before blocking again. 

I changed it to detect only Last_Write:
$aData = _WinAPI_ReadDirectoryChanges($hDirectory, $FILE_NOTIFY_CHANGE_LAST_WRITE, $pBuffer, 50000, 1)

But can't seem to make it iterate once per change. 

  • Developers
Posted

I don't know and haven't looked into the details for that windows call. 

Just for the record, this is in my mind to most simple version of using a GUI and subprocess. They subprocess will end when the gui ends. 

; created by Jos - AutoIt forums
#NoTrayIcon
#include <APIFilesConstants.au3>
#include <EditConstants.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPIError.au3>
#include <WinAPIFiles.au3>
; define folder to monitor..
Global $g_sPath = @DesktopDir & '\Changing folder'
; ----------------------------------------------------------------------------------------
; check for /FileMon_feeder which means it is the subprocess which will monitor the folder
For $x = 1 To $CMDLINE[0]
    Global $T_Var = StringLower($CMDLINE[$x])
    Global $aData
    Global $curcontent = ""
    Select
        Case $T_Var = "/FileMon_feeder"
            ; get main PID from commandline and monitor that.
            Global $H_Cmp = $CMDLINE[$x + 1]
            If Not FileExists($g_sPath) Then
                MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Error', "Folder doesn't exists:" & $g_sPath)
                Exit
            EndIf
            Global $pBuffer = _WinAPI_CreateBuffer(8388608)
            Global $hDirectory = _WinAPI_CreateFileEx($g_sPath, $OPEN_EXISTING, $FILE_LIST_DIRECTORY, $FILE_SHARE_ANY, $FILE_FLAG_BACKUP_SEMANTICS)
            If @error Then
                _WinAPI_ShowLastError('', 1)
            EndIf            ; Run while main script exists.
            While ProcessExists($H_Cmp)
                ConsoleWrite(" Wait for changes..")
                $aData = _WinAPI_ReadDirectoryChanges($hDirectory, BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, $FILE_NOTIFY_CHANGE_DIR_NAME, $FILE_NOTIFY_CHANGE_ATTRIBUTES, $FILE_NOTIFY_CHANGE_SIZE, $FILE_NOTIFY_CHANGE_LAST_WRITE, $FILE_NOTIFY_CHANGE_LAST_ACCESS, $FILE_NOTIFY_CHANGE_CREATION, $FILE_NOTIFY_CHANGE_SECURITY), $pBuffer, 8388608, 1)
                ConsoleWrite(" Something changed?")
                If Not @error And IsArray($aData) Then
                    $curcontent = ControlGetText("Show Folder change", "", "Edit1")
                    For $x = 1 To $aData[0][0]
                        $curcontent &= $aData[$x][0] & " -> " & $aData[$x][1] & @CRLF
                    Next
                    ControlSetText("Show Folder change", "", "Edit1", $curcontent)
                Else
                    _WinAPI_ShowLastError('', 1)
                EndIf
            WEnd
            Sleep(500)
            Exit
    EndSelect
Next
; start this script again to monitor the folder
Global $pid = Run('"' & @AutoItExe & '" "' & @ScriptFullPath & '" /FileMon_feeder ' & @AutoItPID)
;----------------------------------------------------
; Show the GUI
$Form1 = GUICreate("Show Folder change", 493, 263)
$Edit1 = GUICtrlCreateEdit("", 16, 24, 457, 193, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_VSCROLL))
GUISetState(@SW_SHOW, $Form1)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ; close subprocess monitoring the folder
            ProcessClose($pid)
            Exit
    EndSwitch
WEnd

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

I was considering a similar approach, albeit more primitive. 

For now I'll be looking into the multiple returns. 

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
×
×
  • Create New...