Jump to content

two functions run simultaneously


Recommended Posts

You can run two scripts simultaneously without any problem. I suspect that running two functions in the same script at the same time may be possible. What is more usual however is to interrupt a process using a second function, I think this counts. The answer to your question will most likely depend on what these functions are doing. Can you justify doing this. - realize that functions can be called from within other functions, so why would you want to call two functions at the same time?

Edited by czardas
Link to post
Share on other sites

Have your checked out adlibregister() in the help file?

Very little truly is processed simultaneously, and from what Ive read autoit doesn't really do multi-threading. You could try running separate processes and have them talk to each other via a named pipe

Edited by DicatoroftheUSA
Link to post
Share on other sites

There is going to be some lag, but take a look at the functions you can create a separate .au3 file and then using your compiled script use the commandline /AutoIt3ExecuteScript to create a new process of that AutoIt code. I've sometimes done this when I've needed to download a new file but didn't want to halt the entire script just for that (and yes I do know about the background option in InetGet before someone asks.)

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to post
Share on other sites

thanks for the quick replies. I have functions.. one that loads a list of file details (SQLite3), and the rest would be the regular functions for the interface. Now loading takes time since it has to read and load 1000 files or more... and everything halts until loading is finish. This is a serious lag.

Edited by alexlimlexart
Link to post
Share on other sites

Other than running 2 scripts at the same time, there's no way to have 2 functions run at the same time. AdLibs don't run at the same time as other functions, they halt the running function, and run the new one, and then when that's done goes back to the original one if I understand it correctly.

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

Link to post
Share on other sites

alexlimlexart,

One way would be to run a separate script, as guinness suggested.

I put together a simple sample using a ListView to show how easily it can be done.

Main.au3

#include <GUIConstantsEx.au3>

$Form1 = GUICreate("Demo1", 640, 480)
$ListView1 = GUICtrlCreateListView("", 5, 5, 630, 470)

; Call external script to populate ListView while application continues to load normally
$PID = Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptDir & 'DemoLoadValues.au3' & '"')

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

DemoLoadValues.au3

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

; Get a handle to the ListView from your calling script
$ListView1 = ControlGetHandle("Demo1", "", "[CLASS:SysListView32; INSTANCE:1]")

; Here is a simple populate simulation as a proof of concept.
; Your data source would be SQLite, I just used some literals for simplicity.
_GUICtrlListView_InsertColumn($ListView1, 0, "Product ID", 150)
_GUICtrlListView_InsertColumn($ListView1, 1, "Product Name", 200)
For $i = 0 To 2000
    _GUICtrlListView_AddItem($ListView1, "IJ" & $i + 1000)
    _GUICtrlListView_AddSubItem($ListView1, $i, "Product" & $i, 1)
Next

Hope this helps :)

Link to post
Share on other sites

Other than running 2 scripts at the same time, there's no way to have 2 functions run at the same time. AdLibs don't run at the same time as other functions, they halt the running function, and run the new one, and then when that's done goes back to the original one if I understand it correctly.

Indeed you're right, strictly speaking calling two functions simultaneously is impossible. However running simultaneous processes is possible. If you can trigger two processes to run at the same time it would give that impression. However you need a multi-core processor to truly be running them simultaneously.

Edited by czardas
Link to post
Share on other sites

alexlimlexart,

Beside the possibilities offered by the already posted answer, I'd look more closely at why you need such a solution in the first place.

You say querying and having something around 1000 row of your SQLite DB is slow, up to the point you feel the need to parallelize processing. In none of my experiences with SQLite fetching as little as 1000 row is anywhere snail slow as to cause the user take a coffee break. Well, I mean unless you have to run a formidable complex SQL statement or the DB is beyond hundereds of Gb with poor indexing. Both are unlikely for a context where an SQL select "... loads a list of file details".

May I ask you some background detail about your DB schema (including any pragma in force) and the code you use for querying?

I strongly suspect the issue can essentially vanish by fine-tunning the SQL[ite] part.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to post
Share on other sites

Thanks guys for all replies. Jchd, you are probably right but I am now looking into smartee's sample code.

I will be collecting certain inpatient info's from different wards all over the hospital so...

this is assumed that it will reach to about 1000 - 5000 patients in one year.

As a noob in this field (because I am a nurse not a programmer), i fear of losing data so made my Sqlite is very simple.

Each patient will have its own DB3 file and it contains one table and one row and maybe adding one more

table in the future...

The application I am working on right now will do file list to array then read each file, query single row using for loop and

display them in the listview. This is the first approach i could think of fearing of losing huge data if i put it in one DB3 file.

The application will be used by several nurses over the intranet and so making several instances of it from different computers.

The factor that is probably causing the lag is reading several files and not reading a single db3 file but i am more confident in this approach..

Any other suggestions would really help. THANKS!

Edited by alexlimlexart
Link to post
Share on other sites

If you're storing patient records, you should probably be looking at a more robust database development solution. Worrying about losing data by having it in a single database file versus separate file for each patient is only one of the factors you should be looking at. How are you securing your data? What is your backup strategy?

And most importantly is, to me at least, what hospital is going to be using this? No offense intended to either the AutoIt development team or to Richard Hipp and the SQLite development team, but I don't want to be a patient there if you are creating a patient tracking solution using AutoIt and SQLite as your development platform.

Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Link to post
Share on other sites

Alex,

You got about the same fear about DBs that your patients feel right before their surgery! :)

What you've chosen is clearly a terrible solution from a thechnical viewpoint, even if I fully understand why you decided on that.

JohnQSmith is partly right in that a centralized client-server setup is highly recommended in your context. But I also understand that you might not have the admin rights to implement that.

What I disagree is about the alledged lack of robustness of SQLite compared to what comes immediately to mind: MySQL. The latter has many issues that aren't at all on par with a reliable client-server engine. From this point of view, SQLite has much less problems! PostgreSQL is order of magnitude more reliable and stable, but requires even more technical knowledge to setup. Granted, with that low requirements, MySQL can do the job we're talking about easily.

Anyway, it isn't my intention to run into a DB engine flamewar. The problem at hand is that the OP has little choice to implement a satisfactory setup. The AutoIt-SQLite couple isn't the right tool for the job and any client-server engine will demand more priviledges than the OP currently has.

My advice if I may emit one would be to discuss the issue with administrators and hierarchy. If the application is worth its salt, they should find a way to build a decently robust, riskless, supported approach with low setup cost.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to post
Share on other sites

Other than running 2 scripts at the same time, there's no way to have 2 functions run at the same time. AdLibs don't run at the same time as other functions, they halt the running function, and run the new one, and then when that's done goes back to the original one if I understand it correctly.

He did not say what the problem he was trying to solve, so I will exercise my psychic ability more. Thanks for the correction.

Edited by DicatoroftheUSA
Link to post
Share on other sites

Again thanks guys... Well.. I don't have admin rights. This is outside IT department.. mainly involving a small team of nurses that are assigned from different wards. Security isn't an issue because they are the only ones who have access to it. My application will be saved in a shared folder with permissions. Users will only range from 5-10. I chose Autoit and SQlite since these are free and easy to learn at my level of knowledge. If ever this app will be used until next year or so.. then they will be getting huge data...

Situtation:

All db3 files will be staying in one folder (inpatient and discharged file). After my app loads up the db3 files (with sqlite open then shutdown) I tried moving a "no longer needed" db3 file from folder to another folder, but it wouldn't coz its locked.. ending up all db3 in the same place.. and so the app needs to read all files every time it starts.

Edited by alexlimlexart
Link to post
Share on other sites

I'll be back to you about this. Please find a good source for some patience.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By jiaojiaodubai
      I plan to write an Au3 script to automatically install a PPT plug-in.
      Because the button on the installation wizard of the PPT plug-in is not a standard control, I consider writing a while loop to constantly judge the color of a specific location on the installation wizard. When the plug-in is successfully installed, a blue "Start Software" button will appear at this location, so that I can let the script close the installation wizard window.
      But when I used the PixelGetColor function, the script did not get the color of the button on the installation wizard. On the contrary, it went through this foreground window and got the color of my desktop background! However, Au3's window information tool can correctly return the color of this position.
      The following is my script code (due to different configurations, some coordinates may need to be changed when testing on other devices):
      ;~ Run plug-in installation package #RequireAdmin run(@ScriptDir & "\FocoSlide.exe") ;~ In each installation, the number behind this class is different, so you need to use wildcards to match the window. $tittle = "[REGEXPCLASS:HwndWrapper*]" WinWait($tittle) ;~ Change the installation path WinActivate($tittle) Send("+{TAB}") Send("+{TAB}") Send("+{END}") Send("{DELETE}") ControlSend($tittle, "", "", "C:\Program Files (x86)\OfficePlugins\Foco") ;~ Switch focus to "Install" button and enter to confirm Send("+{TAB}") Send("{ENTER}") $wh = WinGetHandle($tittle) ;~ Wait for the "Start Software" button to appear (installation is complete) ;~ Activate the window before each color acquisition to avoid potential errors. WinActivate($tittle) $s = PixelGetColor(763, 533, $wh) ConsoleWrite("color is " & Hex($s, 6) & @CR) While Hex($s) <> "0267EC" Sleep(3000) $s = PixelGetColor(763, 533, $wh) ConsoleWrite("color is " & Hex($s, 6) & @CR) WinActivate($tittle) WEnd ;~ When the blue Start Software button is detected, the installation is completed and the installation wizard is closed. MouseClick("left", 1043, 350) Exit Au3 version: 3.3.16.1
      Operating system: Win11
    • By BillDennis
      I was having problems with dates so I copied the example for _DateAdd from the docs, and THAT wouldn't compile. Am I missing a library or something?

    • By Colduction
      Hi guys!, recently i needed to measure two functions and detect fastest one then i decided to write and share this tiny script for compare, measure and detect fastest functions easily.

      It's such as snippets, i hope you find it useful :)❤
       
      #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 #include-once ; #FUNCTION# ==================================================================================================================== ; Name...........: _FuncSpeedComparator ; Description ...: Compares and measures speed of two functions and shows fastest one. ; Syntax.........: _FuncSpeedComparator($s1stFunc, $s2ndFunc [,$iCallNum, $iResultType]) ; Parameters ....: $s1stFunc - First function that should be compared and measured ; $s2ndFunc - Second function that should be compared and measured ; $iCallNum - [Optional] Number of times function should be called ; Default value is 100 ; $iResultType - [Optional] Type of output must be one of the following numbers: ; 1 ; Results will written in AutoIt Console Output ; 2 ; Results will be as a Message Box ; 3 ; Results will written in AutoIt Console Output and then shows as a Message Box ; Default value is 1 ; Return values .: Success - Returns string ; Failure - Returns False or empty string ; Author ........: Colduction (Ho3ein) ; Modified.......: ; Remarks .......: Function names should be written as string (inside of two Double Quotation or Quotation) to be executed and be measured ; Example .......; _FuncSpeedComparator('ConsoleWrite("10101010101")', 'ConsoleWrite("Hello World!")', 500, 3) ; =============================================================================================================================== Func _FuncSpeedComparator($s1stFunc = "", $s2ndFunc = "", $iCallNum = 100, $iResultType = 1) If Not StringRegExp($s1stFunc, "^[a-zA-Z0-9_]+\x28(.*?)\x29$") Or Not StringRegExp($s2ndFunc, "^[a-zA-Z0-9_]+\x28(.*?)\x29$") Or Not StringRegExp($iCallNum, "^\p{Nd}*$") Or Not StringRegExp($iResultType, "^\p{Nd}*$") Then ; Human mistake preventative stage. Return False Else ; Measure stage. ;; First function measurement. Local $hTimer_1stFunc = TimerInit() For $i = 1 To $iCallNum Execute($s1stFunc) Next Local $iDiff_1stFunc = TimerDiff($hTimer_1stFunc) ;; Second function measurement. Local $hTimer_2ndFunc = TimerInit() For $i = 1 To $iCallNum Execute($s2ndFunc) Next Local $iDiff_2ndFunc = TimerDiff($hTimer_2ndFunc) ; Fastest function detector stage. Local $sFastestFunc = "" If $iDiff_1stFunc = $iDiff_2ndFunc Then $sFastestFunc = "Both of them" ElseIf $iDiff_1stFunc < $iDiff_2ndFunc Then $sFastestFunc = StringRegExpReplace($s1stFunc, "(\x28).*", "") Else $sFastestFunc = StringRegExpReplace($s2ndFunc, "(\x28).*", "") EndIf ; Results stage. Local $sResultText = @CRLF & '#Fastest Function: "' & $sFastestFunc & '"' & @CRLF & @CRLF & '1) "' & StringRegExpReplace($s1stFunc, "(\x28).*", "") & '" time elapsed: (' & $iDiff_1stFunc & ") ms" & @CRLF & '2) "' & StringRegExpReplace($s2ndFunc, "(\x28).*", "") & '" time elapsed: ' & "(" & $iDiff_2ndFunc & ") ms" & @CRLF If $iResultType = 1 Or Not StringRegExp($iResultType, '^[1|2|3]{1}$') Then ; Output as ConsoleWrite. ConsoleWrite($sResultText) ElseIf $iResultType = 2 Then ; Output as MsgBox. MsgBox(64, "Result: " & $sFastestFunc, $sResultText) ElseIf $iResultType = 3 Then ; Output as both ConsoleWrite & MsgBox. ConsoleWrite($sResultText) MsgBox(64, "Result: " & $sFastestFunc, $sResultText) EndIf EndIf EndFunc ;==>_FuncSpeedComparator  
      _FuncSpeedComparator.au3
    • By Emmhor1
      Hi All,

      MAIN QUESTION:
      Is it possible to Call specific function within a GUI

      So I have a script with multiple functions although I don't want to use every function every time.
      My Idea is to create a simple GUI which allows me to select what functions I want to use then run the funtions by clicking a button.
      I have already made a GUI which allows me to select specific .exe's I would like to run after selection it runs the .exe one by one.
      This script is on my work laptops and cannot access it right now.
       
      Who can help me with this?
      GUIcreate
      Func1 
      Func2
      Func3
      Then have a boxes which allows me to select the specif Func.(I used GUIChecked and Unchecked in my other script)
      Then a button which executes/calls the selected functions
    • By AndreasNWWWWW
      I got a question:  i am trying to run different functions based upon what i select in these radio buttons.(code below)
      it needs to check server 1. then run function 1 or function 2 after what i selected in the checkbox.
      once that function is done it moves to the next one, until it has been trough all 5 
       
      iv'e tried using while loops with different while $i equals to something but then i manualy need to go in and edit the script every time.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) $Server2 = GUICtrlCreateLabel("Server2", 216, 95, 41, 17) $server1 = GUICtrlCreateLabel("Server1", 216, 72, 41, 17) $server4 = GUICtrlCreateLabel("Server4", 216, 144, 41, 17) $server3 = GUICtrlCreateLabel("Server3", 216, 119, 41, 17) $server5 = GUICtrlCreateLabel("Server5", 216, 170, 41, 17) $Start = GUICtrlCreateButton("Start", 240, 248, 147, 25) $Checkbox1 = GUICtrlCreateCheckbox("function1", 288, 72, 97, 17) $Checkbox2 = GUICtrlCreateCheckbox("function2", 392, 72, 97, 17) $Checkbox3 = GUICtrlCreateCheckbox("function1", 288, 96, 97, 17) $Checkbox4 = GUICtrlCreateCheckbox("function2", 392, 96, 97, 17) $Checkbox5 = GUICtrlCreateCheckbox("function1", 288, 120, 97, 17) $Checkbox6 = GUICtrlCreateCheckbox("function2", 392, 120, 97, 17) $Checkbox7 = GUICtrlCreateCheckbox("function1", 288, 144, 97, 17) $Checkbox8 = GUICtrlCreateCheckbox("function2", 392, 144, 97, 17) $Checkbox9 = GUICtrlCreateCheckbox("function1", 288, 170, 97, 17) $Checkbox10 = GUICtrlCreateCheckbox("function2", 392, 170, 97, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
×
×
  • Create New...