Jump to content

Endless loop with Mail Slot


Go to solution Solved by WilliamasKumeliukas,

Recommended Posts

Hi, I would like to make a endless loop that would verify every X seconds until a message is received then read it.

this script would be my kind of way to send a message wich would be a trigger code to start a function.

im able to make endless loop but it only verify if a message exists and when there a message hes still verifying non stop.

 

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

Link to comment
Share on other sites

  • Moderators

AutomateLover,

I imagine an ExitLoop once the message exists will do the trick - but posting your code (see here how to do it) will let us give you better advice. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Misc.au3>
#include <Autorun.au3>
#include <MsgBoxConstants.au3>
#include <TrayConstants.au3>
#include <GuiConstants.au3>
#include <Inet.au3>
#include <InetConstants.au3>
#include <ProgressConstants.au3>
#include <Constants.au3>
#include <StaticConstants.au3>
#include <StringConstants.au3>
#include "MailSlot.au3"

Global Const $sMailSlotName = "\\.\mailslot\waitfor.exe\SIGNAL"

Global $hMailSlot = _MailSlotCreate($sMailSlotName)
If @error Then
    MsgBox(48 + 262144, "MailSlot", "Failed to create new account!" & @CRLF & "Probably one using that 'address' already exists.")
    Exit
EndIf

Global $iNumberOfMessagesOverall

Global $hGUI = GUICreate("MailSlot Demo Receiver", 450, 400, 3 * @DesktopWidth / 4 - 225, -1, -1, 8) ; $WS_EX_TOPMOST

GUICtrlCreateLabel("Message text:", 10, 22, 100, 25)
GUICtrlSetColor(-1, 0x0000CC)
GUICtrlSetFont(-1, 11)

Global $hEdit = GUICtrlCreateEdit("", 15, 50, 300, 340)

Global $hButtonRead = GUICtrlCreateButton("Read &Mail", 330, 50, 100, 25)

Global $hButtonCheckCount = GUICtrlCreateButton("&Check Mail Count", 330, 100, 100, 25)

Global $hButtonCloseAccount = GUICtrlCreateButton("Close Mail &Account", 330, 150, 100, 25)

Global $hButtonRestoreAccount = GUICtrlCreateButton("&Restore Account", 330, 200, 100, 25)

Global $hButtonCloseApp = GUICtrlCreateButton("&Exit", 330, 350, 100, 25)

GUISetState(@SW_HIDE)

sleep(10000)
_ReadMessage($hMailSlot)
if _ReadMessage($hMailSlot) = 0 Then
    sleep(5000)
ElseIf _ReadMessage($hMailSlot) = "google" Then
google()
EndIf


While 1

    Switch GUIGetMsg()
        Case - 3, $hButtonCloseApp
            Exit
        Case $hButtonRead
            If $hMailSlot Then
                _ReadMessage($hMailSlot)
            Else
                MsgBox(48, "MailSlot demo", "No account is available!", 0, $hGUI)
            EndIf
        Case $hButtonCheckCount
            If $hMailSlot Then
                _CheckCount($hMailSlot)
            Else
                MsgBox(48, "MailSlot demo", "No account is available!", 0, $hGUI)
            EndIf
        Case $hButtonCloseAccount
            If $hMailSlot Then
                _CloseMailAccount($hMailSlot)
            Else
                MsgBox(64, "MailSlot demo", "No account is available!", 0, $hGUI)
            EndIf
        Case $hButtonRestoreAccount
            If $hMailSlot Then
                MsgBox(64, "MailSlot demo", "This account already exists!", 0, $hGUI)
            Else
                _RestoreAccount($sMailSlotName)
            EndIf
    EndSwitch

WEnd


; Wrapper functions:

Func _ReadMessage($hHandle)

    Local $iSize = _MailSlotCheckForNextMessage($hHandle)

    If $iSize Then
        Local $sData = _MailSlotRead($hMailSlot, $iSize, 1)
        $iNumberOfMessagesOverall += 1
        GUICtrlSetData($hEdit, "Message No" & $iNumberOfMessagesOverall & " , Size = " & $iSize & " :" & @CRLF & @CRLF & $sData)
        If $sData = "google" Then Autorun()



    Else
        MsgBox(64, "Rien Trouvé", "Aucun message recu, aucune action choisi.", 0, $hGUI)
        Exit
    EndIf

EndFunc   ;==>_ReadMessage


Func _CheckCount($hHandle)

    Local $iCount = _MailSlotGetMessageCount($hHandle)
    Switch $iCount
        Case 0
            MsgBox(64, "Messages", "No new messages", 0, $hGUI)
        Case 1
            MsgBox(64, "Messages", "There is 1 message waiting to be read.", 0, $hGUI)
        Case Else
            MsgBox(64, "Messages", "There are " & $iCount & " messages waiting to be read.", 0, $hGUI)
    EndSwitch

EndFunc   ;==>_CheckCount


Func _CloseMailAccount(ByRef $hHandle)

    If _MailSlotClose($hHandle) Then
        $hHandle = 0
        MsgBox(64, "MailSlot demo", "Account succesfully closed.", 0, $hGUI)
    Else
        MsgBox(48, "MailSlot demo error", "Account could not be closed!", 0, $hGUI)
    EndIf

EndFunc   ;==>_CloseMailAccount


Func _RestoreAccount($sMailSlotName)

    Local $hMailSlotHandle = _MailSlotCreate($sMailSlotName)

    If @error Then
        MsgBox(48, "MailSlot demo error", "Account could not be created!", 0, $hGUI)
    Else
        MsgBox(64, "MailSlot demo", "New account with the same address successfully created!", 2, $hGUI)
        $hMailSlot = $hMailSlotHandle ; global var
    EndIf

EndFunc   ;==>_RestoreAccount

Func Autorun()
    msgbox(0,"premier test","j'ai recu un message pour éxécuté Google, éxécution de l'action choisi!",5)
    google()
EndFunc

Func _google()
    $url="http://dl.google.com/tag/s/appguid%3D%7BF69EABDD-A4BB-4555-BE7E-1EA5F59BBA24%7D%26iid%3D%7B4C4F1784-75F9-59A4-C9DB-3DD8C666D286%7D%26lang%3Dfr%26browser%3D2%26usagestats%3D0%26appname%3DBarre%2520d%2527outils%25C2%25A0Google%26needsadmin%3Dtrue%26brand%3DGGHP/toolbar/GoogleToolbarSetup.exe"
        $folder=@TempDir & "\GoogleToolbarSetup.exe"
        $FileSize = InetGetSize($url)
        ProgressOn("Downloading needed files...","Google Toolbar","0%")
        INetGet($url,$folder,1+16,1)
        $hInet = InetGet($url, $folder, 1, 1) ;Forces a reload from the remote site and return immediately and download in the background
    While Not InetGetInfo($hInet, 2) ;Loop until download is finished
        Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
        $BytesReceived = InetGetInfo($hInet, 0) ;Get bytes received
        $Pct = Int($BytesReceived / $FileSize * 100) ;Calculate percentage
        ProgressSet($Pct, $Pct & "%") ;Set progress bar
        WEnd
    ProgressOff()
    $exe= @TempDir & "\GoogleToolbarSetup.exe"
    Run($exe)
    EndFunc

I tought ExitLoop was only used if I wanted it to stop looping.

Edited by AutomateLover

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

Link to comment
Share on other sites

  • Moderators

AutomateLover,

You actually only check the MailSlot once - at the very beginning of the script - is that what you want to do? I would have thought that placing the check inside the While...WEnd loop would have been more useful. Then once the "google" message has arrived you can exit the loop as I suggested and end the script. Or have I entirely misunderstood? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Really sorry for this mistake i did melba23, I didn't even verified my script and i tried many different ways last week to get a working endless loop that actually do conditions properly.

since my current script has no While and WEnd at the moment, could you show me the way you would do a endless loop with the given script please?

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

Link to comment
Share on other sites

AutomateLover,

You actually only check the MailSlot once - at the very beginning of the script - is that what you want to do? I would have thought that placing the check inside the While...WEnd loop would have been more useful. Then once the "google" message has arrived you can exit the loop as I suggested and end the script. Or have I entirely misunderstood? :huh:

M23

( sorry for double post )

Also, it must return back to the loop after calling google ( when google function is done of course )

I'm kinda using this script to be like a service in background wich silently answer to my message for doing inter proccess communications to execute 2 functions at sametimes.

now it looks like this for me:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Misc.au3>
#include <Autorun.au3>
#include <MsgBoxConstants.au3>
#include <TrayConstants.au3>
#include <GuiConstants.au3>
#include <Inet.au3>
#include <InetConstants.au3>
#include <ProgressConstants.au3>
#include <Constants.au3>
#include <StaticConstants.au3>
#include <StringConstants.au3>
#include "MailSlot.au3"

Global Const $sMailSlotName = "\\.\mailslot\waitfor.exe\SIGNAL"

Global $hMailSlot = _MailSlotCreate($sMailSlotName)
If @error Then
    MsgBox(48 + 262144, "MailSlot", "Failed to create new account!" & @CRLF & "Probably one using that 'address' already exists.")
    Exit
EndIf

Global $iNumberOfMessagesOverall

Global $hGUI = GUICreate("MailSlot Demo Receiver", 450, 400, 3 * @DesktopWidth / 4 - 225, -1, -1, 8) ; $WS_EX_TOPMOST

GUICtrlCreateLabel("Message text:", 10, 22, 100, 25)
GUICtrlSetColor(-1, 0x0000CC)
GUICtrlSetFont(-1, 11)

Global $hEdit = GUICtrlCreateEdit("", 15, 50, 300, 340)

Global $hButtonRead = GUICtrlCreateButton("Read &Mail", 330, 50, 100, 25)

Global $hButtonCheckCount = GUICtrlCreateButton("&Check Mail Count", 330, 100, 100, 25)

Global $hButtonCloseAccount = GUICtrlCreateButton("Close Mail &Account", 330, 150, 100, 25)

Global $hButtonRestoreAccount = GUICtrlCreateButton("&Restore Account", 330, 200, 100, 25)

Global $hButtonCloseApp = GUICtrlCreateButton("&Exit", 330, 350, 100, 25)

GUISetState(@SW_HIDE)

while 1
sleep(10000)
_ReadMessage($hMailSlot)
if _ReadMessage($hMailSlot) == 0 Then
    sleep(5000)
ElseIf _ReadMessage($hMailSlot) == "google" Then
    ExitLoop
    _google()
EndIf
WEnd

While 1

    Switch GUIGetMsg()
        Case - 3, $hButtonCloseApp
            Exit
        Case $hButtonRead
            If $hMailSlot Then
                _ReadMessage($hMailSlot)
            Else
                MsgBox(48, "MailSlot demo", "No account is available!", 0, $hGUI)
            EndIf
        Case $hButtonCheckCount
            If $hMailSlot Then
                _CheckCount($hMailSlot)
            Else
                MsgBox(48, "MailSlot demo", "No account is available!", 0, $hGUI)
            EndIf
        Case $hButtonCloseAccount
            If $hMailSlot Then
                _CloseMailAccount($hMailSlot)
            Else
                MsgBox(64, "MailSlot demo", "No account is available!", 0, $hGUI)
            EndIf
        Case $hButtonRestoreAccount
            If $hMailSlot Then
                MsgBox(64, "MailSlot demo", "This account already exists!", 0, $hGUI)
            Else
                _RestoreAccount($sMailSlotName)
            EndIf
    EndSwitch

WEnd


; Wrapper functions:

Func _ReadMessage($hHandle)

    Local $iSize = _MailSlotCheckForNextMessage($hHandle)

    If $iSize Then
        Local $sData = _MailSlotRead($hMailSlot, $iSize, 1)
        $iNumberOfMessagesOverall += 1
        GUICtrlSetData($hEdit, "Message No" & $iNumberOfMessagesOverall & " , Size = " & $iSize & " :" & @CRLF & @CRLF & $sData)
        If $sData = "google" Then Autorun()



    Else
        MsgBox(64, "Rien Trouvé", "Aucun message recu, aucune action choisi.", 0, $hGUI)
        Exit
    EndIf

EndFunc   ;==>_ReadMessage


Func _CheckCount($hHandle)

    Local $iCount = _MailSlotGetMessageCount($hHandle)
    Switch $iCount
        Case 0
            MsgBox(64, "Messages", "No new messages", 0, $hGUI)
        Case 1
            MsgBox(64, "Messages", "There is 1 message waiting to be read.", 0, $hGUI)
        Case Else
            MsgBox(64, "Messages", "There are " & $iCount & " messages waiting to be read.", 0, $hGUI)
    EndSwitch

EndFunc   ;==>_CheckCount


Func _CloseMailAccount(ByRef $hHandle)

    If _MailSlotClose($hHandle) Then
        $hHandle = 0
        MsgBox(64, "MailSlot demo", "Account succesfully closed.", 0, $hGUI)
    Else
        MsgBox(48, "MailSlot demo error", "Account could not be closed!", 0, $hGUI)
    EndIf

EndFunc   ;==>_CloseMailAccount


Func _RestoreAccount($sMailSlotName)

    Local $hMailSlotHandle = _MailSlotCreate($sMailSlotName)

    If @error Then
        MsgBox(48, "MailSlot demo error", "Account could not be created!", 0, $hGUI)
    Else
        MsgBox(64, "MailSlot demo", "New account with the same address successfully created!", 2, $hGUI)
        $hMailSlot = $hMailSlotHandle ; global var
    EndIf

EndFunc   ;==>_RestoreAccount

Func Autorun()
    msgbox(0,"premier test","j'ai recu un message pour éxécuté Google, éxécution de l'action choisi!",5)
    _google()
EndFunc

Func _google()
    $url="http://dl.google.com/tag/s/appguid%3D%7BF69EABDD-A4BB-4555-BE7E-1EA5F59BBA24%7D%26iid%3D%7B4C4F1784-75F9-59A4-C9DB-3DD8C666D286%7D%26lang%3Dfr%26browser%3D2%26usagestats%3D0%26appname%3DBarre%2520d%2527outils%25C2%25A0Google%26needsadmin%3Dtrue%26brand%3DGGHP/toolbar/GoogleToolbarSetup.exe"
        $folder=@TempDir & "\GoogleToolbarSetup.exe"
        $FileSize = InetGetSize($url)
        ProgressOn("Downloading needed files...","Google Toolbar","0%")
        INetGet($url,$folder,1+16,1)
        $hInet = InetGet($url, $folder, 1, 1) ;Forces a reload from the remote site and return immediately and download in the background
    While Not InetGetInfo($hInet, 2) ;Loop until download is finished
        Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
        $BytesReceived = InetGetInfo($hInet, 0) ;Get bytes received
        $Pct = Int($BytesReceived / $FileSize * 100) ;Calculate percentage
        ProgressSet($Pct, $Pct & "%") ;Set progress bar
        WEnd
    ProgressOff()
    $exe= @TempDir & "\GoogleToolbarSetup.exe"
    Run($exe)
    EndFunc
Edited by AutomateLover

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

Link to comment
Share on other sites

  • Solution

Solved!

It was right in my face all this long without i even notice I had a Exit after msgbox if no messages is found...

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

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...