-
October 31st, 2011, 01:27 PM
#1
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
-
October 31st, 2011, 04:33 PM
#2
Re: How does one wait for amount of time
Post some code. Each IMAGE should be able to be rotated
-
October 31st, 2011, 05:07 PM
#3
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.
-
November 1st, 2011, 07:59 AM
#4
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.
-
November 2nd, 2011, 07:44 AM
#5
Re: How does one wait for amount of time
Originally Posted by DataMiser
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.
-
November 2nd, 2011, 11:22 AM
#6
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.
-
November 2nd, 2011, 11:38 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|