Jump to content
Sign in to follow this  
Armand

GUIOnEventMode, can one make a function "Uninteruptable" ?

Recommended Posts

Armand

hey there, i'm using the OnEventMode for my program as it has many controls and different actions so i thought it'll be easier to work it that way.

my issue is showed exactly in the GUI bellow, just run it and while in the middle of an update of the listview click Interrupt and u will see my issue...

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 309, 232, 193, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$ListView1 = GUICtrlCreateListView("DATA GOES HERE|", 30, 5, 241, 196)

$Button2 = GUICtrlCreateButton("Interupt", 100, 205, 100, 25, 0)
GUICtrlSetOnEvent(-1, "Button2Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$stopper = 0
;Create example array.
Dim $aExample[1]
AddEntryInExampleArray("Text")
AddEntryInExampleArray("Else")

While 1
    If $stopper = 0 Then ;Added to stuck the function on the bugged output.
        UpdateListView() 
    EndIf
    Sleep(1000)
WEnd


Func UpdateListView()
    _GUICtrlListView_DeleteAllItems($ListView1)
    For $i = 0 To UBound($aExample)-1
        Sleep(100)
        $aInternal = $aExample[$i]
        For $i2 = 0 To UBound($aInternal)-1
            GUICtrlCreateListViewItem($aInternal[$i], $ListView1)
            Sleep(100) ;So that it'll take it some time...
        Next
    Next
EndFunc

Func AddEntryInExampleArray($text)
    ;Create the internal array
    Dim $aInternal[10]
    For $i = 0 To 9
        $aInternal[$i] = $text&" "&$i
    Next
    
    If $aExample[0] <> "" Then
        ReDim $aExample[UBound($aExample)+1] ;Add 1 entry.
        $aExample[UBound($aExample)-1] = $aInternal ;Place at end.
    Else
        ;Place the new array inside the example.
        $aExample[0] = $aInternal
    EndIf
EndFunc

Func Button2Click()
    AddEntryInExampleArray("NEW")
    ;Refresh new results.
    UpdateListView()
    ;Make it stuck so u can see change.
    MsgBox(0, "Changed?", "Can u see the change?")
    $stopper = 1
EndFunc

Func Form1Close()
    Exit
EndFunc

[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Share this post


Link to post
Share on other sites
martin

hey there, i'm using the OnEventMode for my program as it has many controls and different actions so i thought it'll be easier to work it that way.

my issue is showed exactly in the GUI bellow, just run it and while in the middle of an update of the listview click Interrupt and u will see my issue...

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 309, 232, 193, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$ListView1 = GUICtrlCreateListView("DATA GOES HERE|", 30, 5, 241, 196)

$Button2 = GUICtrlCreateButton("Interupt", 100, 205, 100, 25, 0)
GUICtrlSetOnEvent(-1, "Button2Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$stopper = 0
;Create example array.
Dim $aExample[1]
AddEntryInExampleArray("Text")
AddEntryInExampleArray("Else")

While 1
    If $stopper = 0 Then ;Added to stuck the function on the bugged output.
        UpdateListView() 
    EndIf
    Sleep(1000)
WEnd


Func UpdateListView()
    _GUICtrlListView_DeleteAllItems($ListView1)
    For $i = 0 To UBound($aExample)-1
        Sleep(100)
        $aInternal = $aExample[$i]
        For $i2 = 0 To UBound($aInternal)-1
            GUICtrlCreateListViewItem($aInternal[$i], $ListView1)
            Sleep(100) ;So that it'll take it some time...
        Next
    Next
EndFunc

Func AddEntryInExampleArray($text)
    ;Create the internal array
    Dim $aInternal[10]
    For $i = 0 To 9
        $aInternal[$i] = $text&" "&$i
    Next
    
    If $aExample[0] <> "" Then
        ReDim $aExample[UBound($aExample)+1] ;Add 1 entry.
        $aExample[UBound($aExample)-1] = $aInternal ;Place at end.
    Else
        ;Place the new array inside the example.
        $aExample[0] = $aInternal
    EndIf
EndFunc

Func Button2Click()
    AddEntryInExampleArray("NEW")
    ;Refresh new results.
    UpdateListView()
    ;Make it stuck so u can see change.
    MsgBox(0, "Changed?", "Can u see the change?")
    $stopper = 1
EndFunc

Func Form1Close()
    Exit
EndFunc
If you want a function A to run without being interrupted by function B then you could do this

i) at th estart of function A put $DoNotStopMe = true, and at the end put $DoNotStoMe = false

ii) at the start of function B put If $DoNotStopMe then return.

Obviously $DoNotStopMe must be global.

BTW I think you need to change the first line of the UpdateListView function to

_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView1))


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Armand

@martin

well.. that will stop the function from being interrupted but will also cause the action of the interruption button to be discarded....

-> what i have done by now is to create a global array which will store all the functions that are called while a'$DoNotStopMe' variable is set to true.... these will be automatically pulled out and called at the main loop...

i was just hoping there is some better solution for this issue... i guess there isn't....

P.S -> the given example above is working as is just fine in latest beta.

THANKS A LOT FOR YOUR ATTENTION !!!


[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Share this post


Link to post
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
Sign in to follow this  

×