Run code while a dialog box is shown

Hello!
I am trying to make a script that will show a dialog box and at the same time loop through some code. I cannot find a way to do this, does anybody know how? Below is sort of how I want the code to work.
Thanks!

Code Block applescript
set thedialog to display dialog "A dialog box"
repeat while thedialog = true
set TimeUntilButtonPress to TimeUntilButtonPress + 1
delay 1
end repeat
--This is incorrect, its just an example of how I want the code to work


The standard AppleScript display dialog is modal, so you will need to use something else, for example a window or panel via some AppleScriptObjC or a separate helper application.
Run code while a dialog box is shown
 
 
Q