Solved

Animated Icon

Posted on 2010-09-14
3
389 Views
Last Modified: 2012-05-10
I have a form that when a button is clicked it triggers another form to popup and reads "Waiting" with an animated spinning arrows gif  
The problem is that when the waiting form is displayed the gif is moving then stops and then moves random.  I think the process, LocalDataCache1SyncAgent() which sync's local sql db to server sql 2005 on the parent form seems to be the problem, but am not sure.  I have tried progress bar and it does the same thing, just does not seem to have movement after the process starts on the parent.  I have even tried starting the process off on the parent form with ..Application.DoEvents() and still does not work..

Any ideas to get a continus smooth running gif while the parent process runs would be greatly appreciated.
0
Comment
Question by:H-SC
  • 2
3 Comments
 
LVL 7

Expert Comment

by:klakkas
Comment Utility
The problem is that both forms run in the same thread, so the animation of the first form is blocked by the processing done by the second form.

The solution is to use a backgroundWorker, either in the parent form to call the second one:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button1.Image =anim 'Animation gif
        BackgroundWorker1.RunWorkerAsync()
    End Sub

    Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Dim f2 As New Form2
        f2.Show()
    End Sub


Or (more efficient in my opinion) use the backgroundWorker in the second form:

Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       BackgroundWorker1.RunWorkerAsync()
    End Sub

Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
     'Do the necessary processing
    End Sub

    End Sub
0
 
LVL 7

Accepted Solution

by:
klakkas earned 500 total points
Comment Utility
In general, the best practice is to put all your heavy work in a backgroundWorker, in order to allow the user interface to work without problems.

So, after reading again your description, the best practice ( in my opinion) is the following:

Dim fWait as frmWait
Private Sub btnDoHeavyWork_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoHeavyWork.Click
     fWait = new frmWait
     f.show
     BackgroundWorker1.RunWorkerAsync()
end sub

Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
     'Do the necessary processing
    End Sub

    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
     fWait.close()
    End Sub
0
 
LVL 1

Author Comment

by:H-SC
Comment Utility
klakkas,

Many thanks!  Simply brilliant, not sure why I did not think of the background worker...  It is working smooth!

thanks again
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now