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 7832791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:24:47+00:00 2026-06-02T12:24:47+00:00

I am writing a home WPF app that is obtaining a file from a

  • 0

I am writing a home WPF app that is obtaining a file from a server at a configured interval.

It’s a basic window, with a couple of labels. I have the following

  • Start Time (reflects DateTime the “Start” event was hit
  • Duration (reflects the time the app has been running)
  • Speed (the download speed of the file)

I want to update the Duration on the Main window each second so I have the following code to do this (in a seperate class “RunDownloader.cs”).

    private void StartTickTimer()
    {
        const double interval = 1000;

        if (_tickTimer == null)
        {
            _tickTimer = new Timer
            {
                Interval = interval
            };
            _tickTimer.Elapsed += _ticktimer_Elapsed;
        }

        _tickTimer.Start();
    }

On _ticktimer_Elapsed I call a method in the main window _mainWindow.UpdateTicker();

This does the following.

    public void UpdateTicker()
    {
        var timeStarted = lblTimeStarted.Content.ToString();
        DateTime startTime = DateTime.Parse(timeStarted);
        TimeSpan span = DateTime.Now.Subtract(startTime);

        //ToDo: Output time taken here!
        //lblTimeElapsed.Content =
    }

I have two issues.

  1. I have the following exception when calling lblTimeStarted.Content.ToString(); in UpdateTicker()

        "The calling thread cannot access this object because a different thread owns it."
    
  2. I dont quite know, how to show the duration correctly for lblTimeElapsed.Content from TimeSpan

Thanks in advance for any answers. 😀

  • 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-02T12:24:49+00:00Added an answer on June 2, 2026 at 12:24 pm

    In WPF you cannot update UI objects (that get created on the UI thread) from threads other than the UI thread.
    In order to update UI controls from some other thread (eg a timer thread) you need to use the Dispatcher to run your update code on the UI thread.
    This Question/answer may help you or you will find plenty of info by googling “WPF Dispatcher”.
    An example dispatcher call – the lamda code will get posted off to run on the UI thread:

    Dispatcher.BeginInvoke(new Action(() =>
    {
        text_box.AppendText(formated_msg);
        text_box.ScrollToEnd();
    }));
    

    Alternatively you could replace your existing timer with a DispatchTimer – unlike the timer you are using it ensures that the timer callback is on the UI thread:

    Reasons for using a DispatcherTimer opposed to a System.Timers.Timer are that the DispatcherTimer runs on the same thread as the Dispatcher and a DispatcherPriority can be set on the DispatcherTimer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing my first JQTouch app. When I go from #login to #home , a
I'm learning C# by writing a home library manager. I have a BookController that
I am writing an application, similar to Seti@Home, that allows users to run processing
I'm writing an app and code to start the app on the home key
I am writing an app that allows a user to set the phone's wallpaper
I am writing an iPad app that presents user documents similar to the way
Hi I'm writing an app that has multiple activities. Right now it starts at
I am writing an Android app with two entry points that have intent filters
I am writing a shell script that takes file paths as input. For this
I'm writing a script that has to move some file around, but unfortunately it

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.