Jump to content

Issues with TrayMenu and timing


nitekram
 Share

Recommended Posts

I read another thread that said that once you opened up the menu, all other code stopped. My problem is there seems to be a delay of me clicking and things actually working. I have an example, but basically my code goes out and checks other things, but I still want to be able to interrupt that code if need be.

Here is one example:

#include <TrayConstants.au3>
Opt("TrayMenuMode", 3)

Global $tUIPDisableItem = TrayCreateItem("DISABLE")
TrayCreateItem("")
Global $tExit = TrayCreateItem("EXIT")

Local $TRAY

While 1
    For $x = 0 To 10000
        ConsoleWrite($x & @CRLF)
    Next

    $TRAY = TrayGetMsg()
    Select

        ; delay - checking something else???


        Case $TRAY = $tUIPDisableItem

            If BitAND(TrayItemGetState($tUIPDisableItem), $TRAY_CHECKED) <> $TRAY_CHECKED Then
                TrayItemSetState($tUIPDisableItem, $TRAY_CHECKED)
            Else
                TrayItemSetState($tUIPDisableItem, $TRAY_UNCHECKED)

            EndIf

        Case $TRAY = $tExit ; Exit the loop.
            Exit
    EndSelect
WEnd

If I open up the tray, I would think that this would stop the For Loop from starting again, after it has completed one run. I want to be able to check the box, to stop my script from checking other parts of my program, but have found that sometimes, I have to open the tray menu more than once to be able to make the check stick?

How can I stop all other parts from continuing if I open the tray, so it is waiting for input from a user? Here is the >LINK that says it is supposed to stop execution until the menu is gone - or am I reading it wrong?

 

 

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Are you sure that it's not just the For-loop that teases you? Have you tried to delete the For-loop and place the ConsoleWrite command immediately after While.

When the For-loop is running it's blocking the entire message loop, and making it unresponsive. Because the message loop is spending most of the time executing the For-loop, the message loop is blocked most of the time. You can not expect reliable results from a message loop, that is blocked most of the time. A message loop (in MessageLoop mode) should not be blocked.

Link to comment
Share on other sites

nitekram,

As LarsJ says the for...to loop is interfering with the msg loop.  There are two solutions for this. 

Put the msg loop in the for..to loop like this...

#include <TrayConstants.au3>
Opt("TrayMenuMode", 3)

Global $tUIPDisableItem = TrayCreateItem("DISABLE")
TrayCreateItem("")
Global $tExit = TrayCreateItem("EXIT")

Local $TRAY

While 1

    For $x = 0 To 10000
        ConsoleWrite($x & @CRLF)

        $TRAY = TrayGetMsg()
        Select

            ; delay - checking something else???


            Case $TRAY = $tUIPDisableItem

                If BitAND(TrayItemGetState($tUIPDisableItem), $TRAY_CHECKED) <> $TRAY_CHECKED Then
                    TrayItemSetState($tUIPDisableItem, $TRAY_CHECKED)
                Else
                    TrayItemSetState($tUIPDisableItem, $TRAY_UNCHECKED)

                EndIf

            Case $TRAY = $tExit ; Exit the loop.
                Exit
        EndSelect
    Next
WEnd

or change for...to loop to a non-blocking paradigm and put it in the msg loop like this...

#include <TrayConstants.au3>
Opt("TrayMenuMode", 3)

Global $tUIPDisableItem = TrayCreateItem("DISABLE")
TrayCreateItem("")
Global $tExit = TrayCreateItem("EXIT")

Local $TRAY, $x

While 1

    $TRAY = TrayGetMsg()
    Select

        ; delay - checking something else???


        Case $TRAY = $tUIPDisableItem

            If BitAND(TrayItemGetState($tUIPDisableItem), $TRAY_CHECKED) <> $TRAY_CHECKED Then
                TrayItemSetState($tUIPDisableItem, $TRAY_CHECKED)
            Else
                TrayItemSetState($tUIPDisableItem, $TRAY_UNCHECKED)

            EndIf

        Case $TRAY = $tExit ; Exit the loop.
            Exit
    EndSelect

    if $x < 10000 then
        ConsoleWrite($x & @CRLF)
        $x += 1
    endif

WEnd

which you use depends on what you are doing.  I favor the second choice, where possible.

kylomas 

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

nitekram,

As LarsJ says the for...to loop is interfering with the msg loop.  There are two solutions for this. 

Put the msg loop in the for..to loop like this...

#include <TrayConstants.au3>
Opt("TrayMenuMode", 3)

Global $tUIPDisableItem = TrayCreateItem("DISABLE")
TrayCreateItem("")
Global $tExit = TrayCreateItem("EXIT")

Local $TRAY

While 1

    For $x = 0 To 10000
        ConsoleWrite($x & @CRLF)

        $TRAY = TrayGetMsg()
        Select

            ; delay - checking something else???


            Case $TRAY = $tUIPDisableItem

                If BitAND(TrayItemGetState($tUIPDisableItem), $TRAY_CHECKED) <> $TRAY_CHECKED Then
                    TrayItemSetState($tUIPDisableItem, $TRAY_CHECKED)
                Else
                    TrayItemSetState($tUIPDisableItem, $TRAY_UNCHECKED)

                EndIf

            Case $TRAY = $tExit ; Exit the loop.
                Exit
        EndSelect
    Next
WEnd

or change for...to loop to a non-blocking paradigm and put it in the msg loop like this...

#include <TrayConstants.au3>
Opt("TrayMenuMode", 3)

Global $tUIPDisableItem = TrayCreateItem("DISABLE")
TrayCreateItem("")
Global $tExit = TrayCreateItem("EXIT")

Local $TRAY, $x

While 1

    $TRAY = TrayGetMsg()
    Select

        ; delay - checking something else???


        Case $TRAY = $tUIPDisableItem

            If BitAND(TrayItemGetState($tUIPDisableItem), $TRAY_CHECKED) <> $TRAY_CHECKED Then
                TrayItemSetState($tUIPDisableItem, $TRAY_CHECKED)
            Else
                TrayItemSetState($tUIPDisableItem, $TRAY_UNCHECKED)

            EndIf

        Case $TRAY = $tExit ; Exit the loop.
            Exit
    EndSelect

    if $x < 10000 then
        ConsoleWrite($x & @CRLF)
        $x += 1
    endif

WEnd

which you use depends on what you are doing.  I favor the second choice, where possible.

kylomas 

 

Thanks for your help...I assumed my calling function was eating up to much time, but you proved that. Since, I have cut down the amount of times I call the function, which has allowed me to interrupt the While loop, and get it working.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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