Solved

Animated Icon

Posted on 2010-09-14
3
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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 …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

729 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