Solved

run animated gif on onclick

Posted on 2004-09-15
6
1,052 Views
Last Modified: 2012-05-05
my animated that shows work being done gif does not show when i click on the button.


CODE:

Ani.Visible = true; 'this is the animated gif

///Do Some Work that should take awhile to complete


Ani.Visible = false;

I've found that if I comment the 'Ani.Visible = false' out the gif would appear.

0
Comment
Question by:vinny45
6 Comments
 
LVL 24

Expert Comment

by:Justin_W
ID: 12071422
Is your "work" code running in a different thread?  If so, you need to wait for the thread to complete before making the GIF invisible again.
0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 500 total points
ID: 12071599
CODE:

    System.Threading.Thread workThread = new System.Threading.Thread(new System.Threading.ThreadStart(DoSomeWork));
    workThread.IsBackground = true;
    workThread.Start();

You will need these methods too:

    void ShowAni()
    {
      Ani.Visible = true;
    }

    void HideAni()
    {
      Ani.Visible = false;
    }

    void DoSomeWork()
    {
      Invoke(new System.Threading.ThreadStart(ShowAni));
     
      // Do some work that should take a while to complete
     
      Invoke(new System.Threading.ThreadStart(HideAni));
    }
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12080323
You might be able to use this:

Ani.Visible = true; 'this is the animated gif

Application.DoEvents;

Ani.Visible = false;

Bob
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 10

Expert Comment

by:eternal_21
ID: 12081514
TheLearnedOne, unfortunately that will work as far as displaying the image goes, but GIF animation will not occur.  The form's main thread is busy working, and does not animate the GIF.  The only solution is to move your work into another thread.
0
 

Expert Comment

by:malanois
ID: 12089520
eternal,

I have been working on another thread for the same thing.

how do you go about creating another thread for the gif.

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21133658.html

Try:

showimage

Application.DoEvents <-- add this.

Fill
hideimage

Bob


 
Comment from malanois
Date: 09/16/2004 10:58AM PDT
 Your Comment  


hmmmmm????????

The gif comes up,

however the animation only shows on bar and hangs.???



 
Comment from TheLearnedOne  feedback
Date: 09/16/2004 10:59AM PDT
 Comment  


What happens if you don't do the Fill and don't hide the image?  Does the animation work correctly?

Bob
 
Comment from malanois
Date: 09/16/2004 11:05AM PDT
 Your Comment  


yes it works if i dont hide and unhide


 
Comment from TheLearnedOne  feedback
Date: 09/17/2004 07:01AM PDT
 Comment  


Take a look here:

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21132894.html#12081514

I learned something new, without even having to ask a question :)

Bob
 
Comment from malanois
Date: 09/17/2004 11:53AM PDT
 Your Comment  


that is great

Thank You so Much

:)

MJ
 
Comment from malanois
Date: 09/17/2004 12:43PM PDT
 Your Comment  


Well now you got me thinking,

Im trying to play with this.

Ive searched a couple items about thread and I keep getting errors

 Private thread As System.Threading.Thread

    Public Sub Threading()
        thread = New System.Threading.Thread(showimage)

    End Sub


    Public Sub showimage()
        showbx.Show()
    End Sub
    Public Sub hideimage()
        showbx.Hide()
    End Sub

?????????????????????

MJ
 
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 12092312
malanois, I have converted the code to VB for your convienence:


  Public Sub ShowImage()

    pictureBox.Show()

  End Sub

  Public Sub HideImage()

    pictureBox.Hide()

  End Sub

  Private Sub DoWork()

    ShowImage()

    // Do your work here

    HideImage()

  End Sub

  Private Sub StartDoWork()

    Dim workThread As New System.Threading.Thread(AddressOf DoWork)
    workThread.Start()

  End Sub


Just call StartDoWork() to get the process going!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

20 Experts available now in Live!

Get 1:1 Help Now