Link to home
Start Free TrialLog in
Avatar of tuchfeld
tuchfeld

asked on

Timer does not work during BeginInvoke

Hi. I have a Sub that consumes some time.
it also calls a WebService so it can take few seconds or minutes.
during that time I'd like to run some Form's animation code that wakes on timer Tick.
I'm using BeginInvoke thread method to run MySub
But the timer does not tick during that time (but only after MySub is finished).
Why is that? and how can it be fixed?
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Animate_Notification_icon_Timer.Tick
	'my animation code.
    End Sub

    Friend WithEvents Animate_Notification_icon_Timer As System.Windows.Forms.Timer

    Delegate Sub InvokeDelegateMySub()

    Animate_Notification_icon_Timer.Start()
    Me.BeginInvoke(New InvokeDelegateMySub(AddressOf MySub))

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tuchfeld
tuchfeld

ASKER

please explain
I need to access UI also from MySub.
using thread I get Exception.
What version VB.Net you using?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Your original description stated:

    "But the timer does not tick during that time (but only after MySub is finished)."

Which indicates that you were running MySub (with the WebService) on the main UI thread causing it to lock up and not be able to process the pending Tick() events.

Your solution of putting MyAnimation() into another thread should not work then, UNLESS you also put MySub() into another thread as per my comment here:
https://www.experts-exchange.com/questions/26818813/Timer-does-not-work-during-BeginInvoke.html

Did you put MySub() as well into another thread?

You also asked:

    "Why is that? and how can it be fixed?"

Which I answered by explaining about threads...

Your animation consists of "switching icons in the Notification area".  Did you use Invoke/Delegates to update the UI from your thread?...or did you turn off cross-thread checking?

Anyhoo...good luck.
in My specific case. I don't mind if the form is Blocked during MySub run
as long as the Notification icon is animated (icons are replcaed).
The Form is only for DEBUG mode and inactive in production.
in general I believe You are right ! but it takes some effort to implement and mess this it.
but for my specific case I think my solution "works".
don't you think?
"I don't mind if the form is Blocked during MySub run"

If the form is blocked then it can't update the notification icons.

That is where I'm getting confused.  Your description of the problem and your solution don't match to what I would expect to happen in this type of situation.

Not sure why your solution "works"...just trying to understand.  ;)

If it works then great!...
As I posted 02/14/11 03:59 PM, ID: 34887819
MySub() keeps waiting...
and the Notification icon is animating..
just what I wanted.
Idle_Mind, I really appreciate your information here.
and as i said I might get back here to learn some more.
This, will probably happen when I'll discover that I do want Form UI in production mode.
but I find it time consuming for now to do it.
I keep "my" solution since it works.. for me.
the animation task is very light (switching icons in the Notification area).
Anyway Thanks for the ideas and the background..
I might visit this solution again some day...