B4J Question UI update when running procedure

Artorius

Member
Licensed User
Hi.

I have a procedure which could run for hours, depends on input selection. During this run, I would like to show partial results, let say each 15 minutes. I would like to change the text of few labels and show it. Changing is not a problem, but actual redrawing of UI does not occur.

I was browsing forum and so far I believe Timer object could solve my problem?

BR,
Art
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Using the Threading library, you should run this procedure in a separate Thread. From your long-running procedure, you can call Thread.RunOnGuiThread() and pass it the name of another procedure and an Array of Objects to pass as arguments to this other procedure. It is this other procedure that will do the updating of the UI, since it will run on the main Thread. Blocking the main Thread for hours is not a good idea.

Another option is to have your long-running procedure update the value of a global variable and then your Timer_Tick procedure updates the UI based on the value of this global variable. But you should still have your long-running procedure running in a non-main Thread in order for this to work.
 
Upvote 0

Artorius

Member
Licensed User
Within the form, I set all the parameters I need, and then by pushing on the button the the procedure starts running. The procedure is mainly doing comparisons. The data needed is global and is preloaded in another module. Is there any example of threading?
 
Upvote 0

Artorius

Member
Licensed User
The procedure is compiling crossword. The input data are words and all words of same lenght are stored in byte array (one letter one byte). The largest array is about 50k. I preload all of them and then try to go thru all the combinations for given first word. Main subroutine is binary search.

I could check number of combinations done and on each 1 billion use Msgbox2 to show the progress, but then I need to press OK to run it further, which means I need to be at comp at the time. Maybe would be possible to show msgbox for 10 seconds and then procedure continue automatically?

BTW, I started with Python and it was much too slow (interpreter). B4J code runs approx. 60 times faster :)
 
Upvote 0

Artorius

Member
Licensed User
So I create some dummy sub "DummySub" and when I want UI to be updated, I just call it? I change text property of some labels and then use CallSubDelayed(Me, "DummySub")? Or I need to call the same sub again, like recursion?
 
Upvote 0
Top