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

×
×
  • Create New...