App_start:
ProgressBar.New1
AddTimer("Timer8")
Timer8.Interval = 50
Timer8.Enabled = False
...
Sub Sub1
Timer8.Enabled = true
do something
Timer8.Enabled = false
End Sub
...
Sub Timer8_Tick
Do something with the progressbar
ProgressBar.Value = some value
End Sub
AddTimer("Timer8")
Timer8.Interval = 50
Timer8.Enabled = True
Timer8.Enabled = true
do something
Timer8.Enabled = false
No that's not true. In that example the timer is disabled on entry to the Sub. You enable it and then disable it before leaving the Sub. As it is still disabled when your application gets back to the message loop no timer ticks are generated. If you left it enabled when leaving the Sub all would be fine.If i follow your explanation, i would never be able to enable a timer somewhere outside of the app_start.
As it is still disabled when your application gets back to the message loop no timer ticks are generated. If you left it enabled when leaving the Sub all would be fine.
That is exactly correct and what I was trying to explain.The difference with my other timers appears to be that they are enabled in subs that are called by menus or buttons, the subs end as almost as immediatly, while the sub where i have the issue currently performs something longer operation, and if i understan you right then the timer event will not be handled until the sub returns ( to the main loop...? ).
If you are using message boxes in your debugging code then you will not see what I am trying to explain. Message boxes while they are displayed are pumping the message queue so timer events will get executed while a message box is shown. DoEvents pumps the message queue as well allowing events to run.
App_Start
...
Call Thread(MainThread)
End Sub
Sub MainThread
...
My current program code
...
End Sub
I don't know as I haven't seen the structure of your program and so don't really understand the problem you are having. As I said before, if you post some code so I can see it happening, or not!, I can try to explain how to do what you want.How would the behavior change, if the whole program runs under a thread...?
I have been trying to explain that if you block the main thread with a long running operation then nothing happens as all events run on the main thread. If LoadThumbnail is taking a long time on the main thread you would need to run it on a thread to allow the main thread to handle your timer events and use a Thread event or a flag or some other mechanism to signal the end of the opration.The timer is enabled in a sub before i really start to block the main thread by resizing an image using jpeg.loadthumbnail ....Is the code within the timers stopped if something like jpeg.loadthumbnail is executed in a sub...?
It's not B4P message handling, this is how Windows, and most other GUI based environments works. For simplicity they only allow the main thread to update the GUI otherwise the thread locking for access to the GUI gets horribly complicated.From my current understanding, this should remove the limitations implied by the B4P message handling..?
Sub App_Start
...
AddObject("Jpeg", "Jpeg")
AddImage ("Form1", "Image1", 80,80,100,100)
AddPanel("form14","Panel17",25,70,190,100)
AddLabel("Panel17","Label70",40,5,130,20,"")
AddLabel("Panel17","Label72",25,30,150,30,"")
Panel17.Color = 166,167,217
Label70.FontSize = 13
Label72.FontSize = 9
panel17.Visible = False
label70.Visible = False
label72.Visible = False
Label70.FontColor = 0,0,0
Label70.Color = 166,167,217
Label72.Color = 166,167,217
AddTimer("Timer8")
Timer8.Interval = 50
Timer8.Enabled = False
Jpeg.New1
ProgressBar.New1("Panel17",20,70,150,15)
ProgressBar.Minimum = 0
ProgressBar.Maximum = 100
...
End Sub
Sub AddEvents
AddEvent ("Button15", "Click", "EventManager") '
End Sub
Sub Eventmanager
..
Case "button15" : MySub
..
End Sub
Sub MySub
...
some other code
...
WaitingBox("Form14,"Resize","Please wait...",True)
...
JPEG.LoadThumbnail
WaitingBox("","","",False)
...
MsgBox
End Sub
Sub WaitingBox(Form,Title,Description,ShowHideWaitingBox)
Select ShowHideWaitingBox
Case True :
FormLib.ChangeParent("Panel17",Form)
Label70.Text = Title
Label72.Text = Description
Panel17.Visible = True
Label70.Visible = True
Label72.Visible = True
Panel17.BringToFront
Timer8.Enabled = True
DoEvents
Case False :
Timer8.Enabled = False
Panel17.Visible = False
Label70.Visible = False
Label72.Visible = False
DoEvents
End Select
End Sub
Sub Timer8_Tick
'this will move the waitingbox progressbar
If ProgressBar.Value < 100 Then
ProgressBar.Value = ProgressBar.Value + 1
ProgressBar.Refresh
DoEvents
Else
ProgressBar.Value = 0
End If
End Sub
WaitingBox("Form14,"Resize","Please wait...",True)
[COLOR="DarkGreen"]' you enable the Timer here but call DoEvents straight away
' so the Timer won't have ticked yet so there is nothing for DoEvents to do[/COLOR]
...
JPEG.LoadThumbnail
[COLOR="DarkGreen"]' none of your code can run until this call returns
' the main thread is blocked and there is nothing you can about that
' except move the call to a separate thread[/COLOR]
I can't comment without seeing the code, however a thread cannot "call" another thread so I suspect you are doing something wrong.Is this because my thread calls another thread...?
Don't be frustrated. Showing a progress bar during a blocking operation is not in fact simple at all. In fact it is impposible to give an accurate progress indicator unless the operation taking a long time is designed to implement it - and LoadThumbail isn't, it just runs to completion. You might be better just showing the WaitCursor.I'm very frustrated that i cannot find a solution for such a quite simple function.
I am afraid I don't understand what this has got to do with threadingi cannot use formlib.changeparent in conjunction with threading..can i let appear a panel on top of any form without changing the parent of that panel to that form..?
however a thread cannot "call" another thread so I suspect you are doing something wrong.
Sub App_start
AddEvent ("Button16", "Click", "EventManager")
End Sub
Sub EventManager
Case "button15" : Thread2.Start("MyThread")
End Sub
Sub MyThread
...
WaitingBox
...
End Sub
Sub WaitingBox
...
Thread3.Start(MoveBar)
...
End Sub
Sub MoveBar
...
do something with the bar
...
End Sub
You might be better just showing the WaitCursor.
and LoadThumbail isn't, it just runs to completion.
Quote:
i cannot use formlib.changeparent in conjunction with threading..can i let appear a panel on top of any form without changing the parent of that panel to that form..?
I am afraid I don't understand what this has got to do with threading
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?