This is a migrated thread and some comments may be shown as answers.

Process Error using Timers

4 Answers 77 Views
TransitionControl
This is a migrated thread and some comments may be shown as answers.
ENTERPRISE INTERNATIONAL SAS
Top achievements
Rank 1
ENTERPRISE INTERNATIONAL SAS asked on 02 Feb 2011, 01:00 AM
Hi!


I'm having my UserControl to show Thumbnails (list of images) using transition control. Image changes one to another every 7 sec. and to achieve this I'm using a Timer. Next is a snipped code:

public partial class ctlPublicidad : UserControl
{
Timer m_objTemporizador = new Timer();
List<string> m_vaThumbNails = new List<string>();
 
public ctlPublicidad()
        {
this.InitializeComponent();
IndiceThumbnailActivo = -1;
}
 
// This is execute when UserControl is loaded
private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
MostrarSiguienteImagenThumbNail();
                                m_objTemporizador = new Timer(7000);
                                m_objTemporizador.Elapsed += new ElapsedEventHandler(Temporizador_Elapsed);
                                m_objTemporizador.Start();
}
 
void Temporizador_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            MostrarSiguienteImagenThumbNail();
        }
 
       private void MostrarSiguienteImagenThumbNail()
        {
            Random vnNumeroRandom = new Random();
            int vnEfecto = vnNumeroRandom.Next(1, 7);
            switch (vnEfecto)
            {
                case 1: TransitionControl.Transition = new MotionBlurredZoomTransition();
                        TransitionControl.Duration = new TimeSpan(0, 0, 0, 0, 400);
                        break;
                case 2: TransitionControl.Transition = new FadeTransition();
                        TransitionControl.Duration = new TimeSpan(0, 0, 0, 0, 750);
                        break;
                case 3: TransitionControl.Transition = new LinearFadeTransition() { Angle = 0.3, Darker = 0.3, Thickness = 0.2 };
                        TransitionControl.Duration = new TimeSpan(0, 0, 0, 0, 750);
                        break;
                case 4: TransitionControl.Transition = new WaveTransition() { Angle = 0.5, Amplitude = 0.15 };
                        TransitionControl.Duration = new TimeSpan(0, 0, 0, 0, 750);
                        break;
                case 5: TransitionControl.Transition = new FlipWarpTransition();
                        TransitionControl.Duration = new TimeSpan(0, 0, 0, 0, 750);
                        break;
                case 6: TransitionControl.Transition = new SlideAndZoomTransition();
                        TransitionControl.Duration = new TimeSpan(0, 0, 0, 0, 750);
                        break;
                case 7: TransitionControl.Transition = new RollTransition();
                        TransitionControl.Duration = new TimeSpan(0, 0, 0, 0, 750);
                        break;
            }
 
            TransitionControl.Content = new Image() { Source = new BitmapImage(new Uri(m_vaThumbNails[++IndiceThumbnailActivo], UriKind.RelativeOrAbsolute)) };
        }
}

First image is showed fine, but when timer elapsed is reached, exception is thrown when try to change to another transition effect. Error is:
"The calling thread can not access this object because the owner is another thread". How can I do to achieve this thumbnail???


thanks

4 Answers, 1 is accepted

Sort by
0
ENTERPRISE INTERNATIONAL SAS
Top achievements
Rank 1
answered on 02 Feb 2011, 04:28 PM
Hi!

I forgot!, UserControl is used in a Windows Application
0
Accepted
George
Telerik team
answered on 07 Feb 2011, 01:12 PM
Hello Ramiro,

 
I would suggest you to use the DispatcherTimer class, instead of Timer.

I hope this helps! 

Kind regards,
George
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
ENTERPRISE INTERNATIONAL SAS
Top achievements
Rank 1
answered on 08 Feb 2011, 12:12 AM
Hi!


Can you help me by using DispatcherTimer class sample, thanks
0
ENTERPRISE INTERNATIONAL SAS
Top achievements
Rank 1
answered on 09 Feb 2011, 05:33 PM
I've found solution as you told me, thanks very much for your help!!
 
Tags
TransitionControl
Asked by
ENTERPRISE INTERNATIONAL SAS
Top achievements
Rank 1
Answers by
ENTERPRISE INTERNATIONAL SAS
Top achievements
Rank 1
George
Telerik team
Share this question
or