Modeless Form timer does not tick until after processing is complete

Modeless Form timer does not tick until after processing is complete

david_rock
Enthusiast Enthusiast
584 Views
3 Replies
Message 1 of 4

Modeless Form timer does not tick until after processing is complete

david_rock
Enthusiast
Enthusiast

Hello,

 

I have a modeless form that I have added a timer control.

 

On OK button click I have

 

Timer1.Interval = 1000
Timer1.Start()

 

And have the following:

 

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            If uxProgressBar.Value + 1 < uxProgressBar.Maximum Then
                uxProgressBar.Value = uxProgressBar.Value + 1
            Else
                Timer1.Stop()
            End If
    End Sub

However it seems that my progress bar does not move until after the processing is complete.

 

Any ideas?

 

Kind Regards

David

 

0 Likes
585 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Dear David,

 

To do you have to use Invoke method. Timer tick is not working.

 

Steps:

 

 

Step 1: Make function asyn.

Step 2: Invoke progress bar method.

 

Example:

 

private async void funcationName()

{

  //  Assigning maximum value for progress bar

 

  progressBar_Part.Invoke(new System.Action(() => this.progressBar_Part.Maximum = Count));

 

// Show  status on lable;

  this.label_progress_part.Invoke(new System.Action(() => this.label_progress_part.Text = "Processing Elements : " + (i + 1) + "/" + count));
  this.Invoke(new System.Action(() => this.Refresh()));

 

// Increasing Progress bar
await Task.Run(new System.Action(() => { this.progressBar_Part.Invoke(new System.Action(() => this.progressBar_Part.Value = i + 1)); }));
await Task.Run(new System.Action(() => { this.Invoke(new System.Action(() => this.Refresh())); }));

 

}

 

 

0 Likes
Message 3 of 4

david_rock
Enthusiast
Enthusiast

Thank you for the reply.

 

I am able to move the progressbar along. The main think I am after is perhaps a background worker example of a timer as the forms timer is not ticking.

 

I need to use the timer so that the progress bar continues to move during a long process, such as synchronizing and printing.

 

Otherwise the progress bar appears jerky.

 

Kind Regards

David

0 Likes
Message 4 of 4

jeremytammik
Autodesk
Autodesk

Dear David,

 

I have implemented various timers running in a modeless context in a separate thread, e.g. to raise an external Revit event at certain intervals, e.g. here:

 

http://thebuildingcoder.typepad.com/blog/2013/12/replacing-an-idling-event-handler-by-an-external-ev...

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes