Fire "empty" event to prevent freezing?

BlitzMax Forums/MaxGUI Module/Fire "empty" event to prevent freezing?

Htbaa(Posted 2009) [#1]
Is it possible to, while executing some heavy operation, to fire empty events during the execution of the operation so Windows doesn't think the application is freezing and just update the gadgets (like a progressbar)?

I'm currently writing an application that'll upload a number of files. If these are big files then of course it's going to take a while. In bah.libcurl I can set a progressCallback that tells me how much data has been uploaded. At every call I update my progressbar. Which works, but due to Windows thinking it's freezing it soon stops redrawing the progressbar. In my progressCallback, which is called every second or so, I use a DebugLog to see if something is happening, and indeed, it is.

So. Would firing an empty event solve this and just update the progressbars? If so, how do I fire my empty event? Or would threading be the way to go?


Brucey(Posted 2009) [#2]
You might get away with calling PollSystem.


Htbaa(Posted 2009) [#3]
Looks like I'm getting away with it :-). At least now I can get to see some visual progress. Thanks.


SebHoll(Posted 2009) [#4]
Yep, PollSystem() is the function you call to let the system do its stuff during long loops.


Htbaa(Posted 2011) [#5]
Sorry for bringing up this old topic, but I'm running into some problems again.

I've been using PollSystem for a while now and it always worked fine. But due to some API changes my application stopped functioning, so I had to make some changes and do a rebuild. There has been over a year between these builds, so lots of module versions have changed.

I'm using MaxGUI 1.41 with BlitzMax 1.41, together with the latest versions of bah.libcurlssl with OpenSSL 1.0.0.4 and my own htbaapub.rest and htbaapub.rackspacecloudfiles module.

But for some reason the application freezes again even with the PollSystem call in place.

codelink
	Function progressFunction:Int(data:Object, dltotal:Double, dlnow:Double, ultotal:Double, ulnow:Double)
		Local updater:TProgressBarUpdater = TProgressBarUpdater(data)

		If TBackup.backupDirectory.Length > 0
			updater.currentFileSize = ulnow
			updater.currentFileTotalSize = ultotal
		Else If TBackup.restoreDirectory.Length > 0
			updater.currentFileSize = dlnow
			updater.currentFileTotalSize = dltotal
		End If

		updater.UpdateProgressBars()
		PollSystem()

		Return 0
	End Function


This is a callback function passed down to libcurlssl to execute some tasks whilst progressing with a upload/download action.

The updater.UpdateProgressBars() updates 2 progress bars and updates a text label. Normally after the PollSystem() the gadgets would redraw, but this is no longer the case and the form just freezes, when checking a debug window it's processing downloads/uploads just fine, it's just seems that the PollSystem call is being ignored or something.

When I add the PollSystem call to another place (not in this actual file, but in my debug version) it's still not redrawing my gadgets. To add some context to this code, messages are constantly being sent to this message handler so PollSystem should execute every few seconds or so.

Yet, it's still being ignored. I'm building it with the GuiApp flag, but this doesn't seem to matter anything in my end results.

Any pointers on where to look?

Strange thing is that when I'm instructing the program to download files I see the progress bars updating. But not when doing the uploading. Which is strange because both instructions use the same messenger. Although it does freeze up when trying to open a menu. Which it didn't in the past.

Last edited 2011

Last edited 2011

Last edited 2011


jsp(Posted 2011) [#6]
Could you try to use WaitSystem() instead of PollSystem(), if that makes any difference?
May add a little delay to give the system some time to update during heavy processing.


Htbaa(Posted 2011) [#7]
The mainloop already uses WaitSystem whereas at the parts I want to update my gadgets I call PollSystem.

Instead of calling PollSystem, can't I just fire off an event that makes sure the gadgets are redrawn?

Currently to end-users it appears the application is crashing as well as to Windows (not-responding) even though it's doing fine. It's just that the front-end freezes.


jsp(Posted 2011) [#8]
Firing an additional event would not help me thinks.
When it looks like frozen there is no time for the system to recognize it's still running.
Can't you give some more time back to the system?
Even if you used already WaitSystem() in your mainloop I would give it a try and exchange the PollSystem as mentioned above.


Htbaa(Posted 2011) [#9]
I did try replacing the PollSystem with another WaitSystem call but it makes no difference at all.

I've really got no clue what's wrong though, as in the past the gadgets updated fine. I can't for the life find anything suspicious in changelogs or certain Windows updates. Very annoying.


Chalky(Posted 2011) [#10]
when checking a debug window it's processing downloads/uploads just fine, it's just seems that the PollSystem call is being ignored or something.

Is function progressFunction() definitely being [repeatedly] called from within whatever code is doing the download/upload processing?


Htbaa(Posted 2011) [#11]
Ehm yes, basically libcurl keep calling that function to give updates on download progress, how many bytes have been downloaded and how many there's left.

The only time when it does update for a moment is when downloading larger files, but when clicking in the GUI it all freezes up.

When syncing it mainly does HEAD requests, so it isn't even called at all, but the main loop should have returned to the beginning in that case so an update to the GUI should've been issued.


Chalky(Posted 2011) [#12]
Sorry - I didn't mean "have you coded it correctly", I meant is the function actually getting called by the system - or is all CPU time being hogged by the download/upload process - resulting in progressFunction never being executed (or maybe only once or twice)?


SLotman(Posted 2011) [#13]
Try the opposite: change WaitSystem to Pollsystem. From bmax docs:


WaitSystem returns control back to the operating system, waiting until an event such as a keystroke or gadget action occurs.
Note that WaitSystem may wait indefinitely if there is no possibility of any events occuring, so use with caution.



Maybe that's what happening?


Htbaa(Posted 2011) [#14]
@Chalky I didn't take that as a "did you code it correctly"-question. My bad? Yes, when doing the downloading that function is being called. But also when it's not being called the UpdateProgressBars() method is being called in the message loop.

@SLotman I already tried that. Makes no difference at all. Am going to try a FLTK build to see if that would make a difference. Just to see if it's native Windows stuff that's giving me these headaches.

Edit: Nope, FLTK build didn't make a difference, aside from making it look really ugly.

Last edited 2011