CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 1999
    Location
    Fort Worth Texas
    Posts
    614

    Question How does one wait for amount of time

    I have a .net 4.0 VB WPF application where websites, PDF files, pictures, and such are selected via buttons to be displayed. I am trying to set up a feature that rotates thru those web sites, PDF, files pictures, etc. staying on each one maybe 1 miniute or 5 minutes. While it is staying on a specific site a user might select a button which would then jump out of the wait and go to that site, picture or file. I do not know how to do this can someone give me a hint, or existing code or example?

    Thank you

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How does one wait for amount of time

    Post some code. Each IMAGE should be able to be rotated
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    May 1999
    Location
    Fort Worth Texas
    Posts
    614

    Smile Re: How does one wait for amount of time

    Sorry I wasn't meaning rotate the web site, file, or PDF I was meaning go to a web site and stay there for x number of minutes and then go to another site, or file or PDF, etc. Let me explain futher the WPF application has a web browser control in it. When the application starts it points to a specific web site and remains there until someone clicks one of the various buttons on the WPF application window to go to another URL or PDF. I want to add the feature that when the applications starts it shows a specific web page like it does now and after x number of minutes it goes to another site or a PDF file just as if someone had click one of the buttons. Someone would still be able to click one of the various buttons to go to a site of file rather than wait for the rotating loop to take them there.

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: How does one wait for amount of time

    You could use a timer, assuming they are available in WPF apps.
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: How does one wait for amount of time

    Quote Originally Posted by DataMiser View Post
    You could use a timer, assuming they are available in WPF apps.
    Yes they are...

    Code:
        Private timer As System.Windows.Threading.DispatcherTimer
    
        Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
            timer = New System.Windows.Threading.DispatcherTimer()
            timer.Interval = TimeSpan.FromMilliseconds(100)
            AddHandler timer.Tick, AddressOf timer_Tick
            Me.timer.Start()
    
        End Sub
    
        Sub timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
            'This sub will be called ~ every 100ms
        End Sub
    In the tick event you can implement a countdown and select the next target..
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  6. #6
    Join Date
    May 1999
    Location
    Fort Worth Texas
    Posts
    614

    Re: How does one wait for amount of time

    Timer will work except I get an exception about object belonging to an existing thread. This is a WPF applicaton written in VB.NET with a Web Browser control in it. Here is a shorted version of the code being used from the main window class:

    Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    ' Setup Timer
    objTimer = New Timer(5000)
    AddHandler objTimer.Elapsed, New ElapsedEventHandler(AddressOf rotateHandler)


    'Set default URI to navigate to CNN News
    ' Go to the default web page by calling Navigate method
    Me.WebBrowser1.Navigate(("http://www.cnn.com/"))

    ' Set rotate value to -1 to refer to first URL. roate value will be
    ' incremented in timer handler. A value of 0 will refer to first URL
    iRotateValue = -1

    ' Enable the Time
    objTimer.Enabled = True

    End Sub

    ' Rotate Handler
    Public Sub rotateHandler(ByVal sender As Object, ByVal e As ElapsedEventArgs)

    ' Increment the rotate index
    iRotateValue = iRotateValue + 1

    ' Use case statement to select next URL to go to
    Select Case iRotateValue

    Case 0

    ' Go to the beginning web page by calling Navigate method
    Me.WebBrowser1.Navigate(("http://www.cnn.com/"))


    Case 1
    ' Fox News
    ' Go to the Fox News web page by calling Navigate method
    Me.WebBrowser1.Navigate(("http://video.foxnews.com/"))

    Case 2

    ' Weather Channel
    ' Go to the Waether Channel web page by calling Navigate method
    Me.WebBrowser1.Navigate((""http://www.weather.com/weather/today/Fort+Worth+TX+76102"))

    ' Reset roate value to -1 so as to start again with CNN at the next timer handling
    iRotateValue = -1

    End Select

    End sub

    The first time the handler is called it fails on the I get an erorr saying "The calling thread cannot access this object because a different thread owns it." on the Fox news naviation line in Case one " Me.WebBrowser1.Navigate(("http://video.foxnews.com/")) "

    I am not how to construct this.

  7. #7
    Join Date
    May 1999
    Location
    Fort Worth Texas
    Posts
    614

    Exclamation Re: How does one wait for amount of time

    Thank you GremlinSA and everyone else. The DispatchTimer did the trick!!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured