Solved

Animated Icon

Posted on 2010-09-14
3
394 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
ID: 33672383
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
ID: 33672443
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
ID: 33673250
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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