Douglas Farias Expert Licensed User Longtime User Sep 17, 2014 #1 hi all i m trying to found on the forum about do events i fint this DoEvents Processes waiting messages in the messages queue. DoEvents can be called inside lengthy loops to allow the program to update its UI. Other waiting events will not be handled by DoEvents. but i dont found examples off use, can someone tell me what is do events and show a simple examples where use this, show this working, please i really want to know what is this *-* if u have a simple example code show me the doevents in action pls
hi all i m trying to found on the forum about do events i fint this DoEvents Processes waiting messages in the messages queue. DoEvents can be called inside lengthy loops to allow the program to update its UI. Other waiting events will not be handled by DoEvents. but i dont found examples off use, can someone tell me what is do events and show a simple examples where use this, show this working, please i really want to know what is this *-* if u have a simple example code show me the doevents in action pls
lemonisdead Well-Known Member Licensed User Longtime User Sep 17, 2014 #2 Hello Douglas, Have you already seen this post ? Upvote 0
Douglas Farias Expert Licensed User Longtime User Sep 17, 2014 #3 hi man, i see now but the stevel05 only say to dont is good use doevents on big loops, but i want know what exacty do events make *-* have one code with this working? and where is recomended to use? Upvote 0
hi man, i see now but the stevel05 only say to dont is good use doevents on big loops, but i want know what exacty do events make *-* have one code with this working? and where is recomended to use?
S sorex Expert Licensed User Longtime User Sep 17, 2014 #4 I cause the app to update itself so that you don't get these "app is not responding , close or wait?" notifications. Upvote 0
I cause the app to update itself so that you don't get these "app is not responding , close or wait?" notifications.
Douglas Farias Expert Licensed User Longtime User Sep 17, 2014 #5 i see this mensage sometimes Upvote 0
Computersmith64 Well-Known Member Licensed User Longtime User Sep 19, 2014 #6 Douglas Farias said: hi man, i see now but the stevel05 only say to dont is good use doevents on big loops, but i want know what exacty do events make *-* have one code with this working? and where is recomended to use? Click to expand... Hi Douglas, One good example is the roll function I use in my Yahtzee game. I have 5 dice & I want to generate 8 random numbers for each die when the user hits the roll button. If I just set up a loop like this: Code: Copy For iCnt = 0 to 4 For iCnt2 = 0 to 7 imgDie(iCnt).Bitmap = LoadBitmap(File.DirAssets, Rnd(1, 7) & ".png") Next Next Then the UI will only be updated once both loops have finished. So if I want the user to see the effect of each die rolling in turn (& each number generated for each die) then I just use a DoEvents like this: Code: Copy For iCnt = 0 to 4 For iCnt2 = 0 to 7 imgDie(iCnt).Bitmap = LoadBitmap(File.DirAssets, Rnd(1, 7) & ".png") DoEvents Next Next Doing this means that every time a random number is generated & the related image is loaded, the UI will be updated & the user will see the result for a fraction of a second before the next roll completed. This gives the effect of each die rolling in turn. Hope this helps explain it. - Colin. Upvote 0
Douglas Farias said: hi man, i see now but the stevel05 only say to dont is good use doevents on big loops, but i want know what exacty do events make *-* have one code with this working? and where is recomended to use? Click to expand... Hi Douglas, One good example is the roll function I use in my Yahtzee game. I have 5 dice & I want to generate 8 random numbers for each die when the user hits the roll button. If I just set up a loop like this: Code: Copy For iCnt = 0 to 4 For iCnt2 = 0 to 7 imgDie(iCnt).Bitmap = LoadBitmap(File.DirAssets, Rnd(1, 7) & ".png") Next Next Then the UI will only be updated once both loops have finished. So if I want the user to see the effect of each die rolling in turn (& each number generated for each die) then I just use a DoEvents like this: Code: Copy For iCnt = 0 to 4 For iCnt2 = 0 to 7 imgDie(iCnt).Bitmap = LoadBitmap(File.DirAssets, Rnd(1, 7) & ".png") DoEvents Next Next Doing this means that every time a random number is generated & the related image is loaded, the UI will be updated & the user will see the result for a fraction of a second before the next roll completed. This gives the effect of each die rolling in turn. Hope this helps explain it. - Colin.
S sorex Expert Licensed User Longtime User Sep 19, 2014 #8 also notice that this creates a slowdown. if you really need it and the loop is long don't do it on each iteration but every 100 or so. Upvote 0
also notice that this creates a slowdown. if you really need it and the loop is long don't do it on each iteration but every 100 or so.
Loris Anoardi Member Licensed User Longtime User Apr 3, 2015 #9 I'm using Doevents but i haven't success. I want to show a progressdialogshow before executing an intense cycle for loading an array. The problem: the progress dialog appears at the end of this cycle, even if i use DoEvents. How can i resolve? Thank you for help Loris Anoardi Upvote 0
I'm using Doevents but i haven't success. I want to show a progressdialogshow before executing an intense cycle for loading an array. The problem: the progress dialog appears at the end of this cycle, even if i use DoEvents. How can i resolve? Thank you for help Loris Anoardi
DonManfred Expert Licensed User Longtime User Apr 3, 2015 #10 Loris Anoardi said: How can i resolve? Click to expand... Dont block the main thread. Instead do your intensive work in another thread (maybe with the threading library or a service). Using DoEvents CAN be a WORKAROUND in SOME cases but most probably it should not needed to use it. If you do need it then your code is probably wrong. Upvote 0
Loris Anoardi said: How can i resolve? Click to expand... Dont block the main thread. Instead do your intensive work in another thread (maybe with the threading library or a service). Using DoEvents CAN be a WORKAROUND in SOME cases but most probably it should not needed to use it. If you do need it then your code is probably wrong.
Erel B4X founder Staff member Licensed User Longtime User Apr 3, 2015 #11 Calling DoEvents inside the loop (not every iteration) will cause the dialog to show. Though in most cases there are better ways to solve the problem. What makes your code slow? Upvote 0
Calling DoEvents inside the loop (not every iteration) will cause the dialog to show. Though in most cases there are better ways to solve the problem. What makes your code slow?
Mikonios Active Member Licensed User Longtime User Dec 29, 2015 #12 After several tests I get the impression that doevents generate harmful effects. A doevents after a callsubdelay, works fine. However, if I throw a Doevents after a SMTP.Send, blocks the execution of the event SMTP_MessageSent. Similarly a Doevents after a OnMapLoadedCallback1.Initialize ("OnMapLoadedCallback1") stops the event ejeucion OnMapLoadedCallback1_MapLoaded It does this mean that stops DOEVENTS event management to prioritize the message queue ?? Upvote 0
After several tests I get the impression that doevents generate harmful effects. A doevents after a callsubdelay, works fine. However, if I throw a Doevents after a SMTP.Send, blocks the execution of the event SMTP_MessageSent. Similarly a Doevents after a OnMapLoadedCallback1.Initialize ("OnMapLoadedCallback1") stops the event ejeucion OnMapLoadedCallback1_MapLoaded It does this mean that stops DOEVENTS event management to prioritize the message queue ??
lemonisdead Well-Known Member Licensed User Longtime User Dec 29, 2015 #13 Mikonios said: It does this mean that stops DOEVENTS event management to prioritize the message queue ?? Click to expand... Not at all. But if you have events waiting they can slow down the whole process. For example, the SMTP routine you are talking about should be better put in a service Edit : from the documentation DoEvents can be called inside lengthy loops to allow the program to update its UI. Other waiting events will not be handled by DoEvents. Click to expand... https://b4x.com/android/help/core.html#keywords_doevents Last edited: Dec 29, 2015 Upvote 0
Mikonios said: It does this mean that stops DOEVENTS event management to prioritize the message queue ?? Click to expand... Not at all. But if you have events waiting they can slow down the whole process. For example, the SMTP routine you are talking about should be better put in a service Edit : from the documentation DoEvents can be called inside lengthy loops to allow the program to update its UI. Other waiting events will not be handled by DoEvents. Click to expand... https://b4x.com/android/help/core.html#keywords_doevents
Mikonios Active Member Licensed User Longtime User Dec 29, 2015 #14 Two examples :: 1. Tasker App launched by 1:30 every day, collects data from Web's, updated SQLite databases and eventually send mail. .- With 20 minutes to process DOEVENTS ago, and after nine hours not send the mail. I open the device, the app appears in the foreground and automatically launches the mail and finish the croissant. NotOk. .- Eliminated DOEVENTS and send mail immediately ending the App. Ok. 2. gmaps App .- With DoEvents after 45 minutes OnMapLoadedCallback1_MapLoaded not launch event. NotOk. .- Eliminated DOEVENTS OnMapLoadedCallback1_MapLoaded event and launches immediately. Ok. So how long it slows down with DOEVENTS App? Edit:: The process shows me that DOEVENTS stops natural events. Last edited: Dec 29, 2015 Upvote 0
Two examples :: 1. Tasker App launched by 1:30 every day, collects data from Web's, updated SQLite databases and eventually send mail. .- With 20 minutes to process DOEVENTS ago, and after nine hours not send the mail. I open the device, the app appears in the foreground and automatically launches the mail and finish the croissant. NotOk. .- Eliminated DOEVENTS and send mail immediately ending the App. Ok. 2. gmaps App .- With DoEvents after 45 minutes OnMapLoadedCallback1_MapLoaded not launch event. NotOk. .- Eliminated DOEVENTS OnMapLoadedCallback1_MapLoaded event and launches immediately. Ok. So how long it slows down with DOEVENTS App? Edit:: The process shows me that DOEVENTS stops natural events.