Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8004539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:56:50+00:00 2026-06-04T16:56:50+00:00

Hi all my simple code looks like this private void flipForeverever(object sender, EventArgs args)

  • 0

Hi all my simple code looks like this

    private void flipForeverever(object sender, EventArgs args)
    {


            moveYs = new DoubleAnimation();
            m2oveYs = new DoubleAnimation();

            try
            {
                sf.Remove(this);
                sf.Children.Clear();

            }
            catch (Exception e)
            {

            }

            if (firstPanelAngle == 360)
            {
                moveYs.To = 180;
                moveYs.From = 0;
            }
            else
            {
                moveYs.To = 360;
                moveYs.From = 180;
            }




            if (secondPanelAngle == 360)
            {
                m2oveYs.To = 180;
                m2oveYs.From = 0;
            }
            else
            {
                m2oveYs.To = 360;
                m2oveYs.From = 180;
            }



            sf = (Storyboard)FindResource("Storyboard1");
            Storyboard.SetTargetName(moveYs, "rotatePanel");
            Storyboard.SetTargetProperty(moveYs, new                                          thisPropertyPath(AxisAngleRotation3D.AngleProperty));

            Storyboard.SetTargetName(m2oveYs, "rotateSecond");
            Storyboard.SetTargetProperty(m2oveYs, new PropertyPath(AxisAngleRotation3D.AngleProperty));

            sf.Children.Add(moveYs);
            sf.Children.Add(m2oveYs);
           // sf.RepeatBehavior = RepeatBehavior.Forever;

            if (flipForever)
            {
            sf.Completed += new EventHandler(delaythespin);

                 sf.Begin(this);




        }
    }

    private void delaythespin(object sender, EventArgs args)
    {
        sf.Stop(this);

        System.Timers.Timer timer = new System.Timers.Timer(500);
        timer.Elapsed += new System.Timers.ElapsedEventHandler(flipForeverever);

        timer.Enabled = true;
         firstPanelAngle = rotatePanel.Angle;
        secondPanelAngle = rotateSecond.Angle;
        timer.Start();


    }

So basically i call flipForeverever through a click call and it is supposed to loop forever until i set flipforever to false… But then it is giving me this error…

The calling thread cannot access this object because a different thread owns it.

Any help will really be appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:56:51+00:00Added an answer on June 4, 2026 at 4:56 pm

    It sounds like you might be having thread affinity problems. Have you tried using a DispatcherTimer instead of a System.Timers.Timer?

    private DispatcherTimer _timer;
    
    private void GoButton_Click(object sender, RoutedEventArgs e)
    {
        _timer = new DispatcherTimer();                // create timer
        _timer.Interval = new TimeSpan(0, 0, 1);       // tick every 1s
        _timer.Tick += new EventHandler(_timer_Tick);  // method to call
        _timer.Start();                                // start timer
    }
    
    void _timer_Tick(object sender, EventArgs e)
    {
        // we should be on the correct thread now
        GoButton.Background = Brushes.Aqua;
    }
    

    Or, if you need to use System.Timers.Timer, use Invoke or BeginInvoke to get on the correct thread after the timer fires?

    private System.Timers.Timer _timer;
    
    private void GoButton_Click(object sender, RoutedEventArgs e)
    {
        _timer = new System.Timers.Timer(1000);
        _timer.Elapsed += new System.Timers.ElapsedEventHandler(_timer_Elapsed);
        _timer.Start();
    }
    
    void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        // use Dispatcher.Invoke on the UI object that you want to modify
        // to get on the correct thread for that UI object
        GoButton.Dispatcher.Invoke((ThreadStart)(() =>
        {
            GoButton.Background = Brushes.Aqua;
        }));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple code in my user_controller.rb file #listing all users def index
Title says all. Sample code: ArrayList<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>(); HashMap<String, Object>
enter code here Hi All, I have a simple windows service application that connects
This is mainly a thought experiment. So this all is sample code. My goal
my sample code is here include 'simple_html_dom.php'; function get_all_links($url){ global $host; $html = new
Morning All, I was hoping someone could help or provide some sample code for
Hey all, let's jump straight to a code sample to show how ECMAScript/JavaScript/AS3 can't
right now i am simply ftping everything (all of my source code included) but
All the simple examples of geocoding load a hard-coded long/lat pair and then, after
I have a map that reads an XML file; it's all very simple and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.