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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:39:16+00:00 2026-06-02T00:39:16+00:00

I am having problems converting my DispatcherTimer syntax to the Thread Timer. When i

  • 0

I am having problems converting my DispatcherTimer syntax to the Thread Timer. When i run my application suddenly it shuts down without any error.

Basically i want the timer to execute 2 methods every 5 seconds.

EDIT: The 2 methods are updating the UI.
I am trying to attempt to get rid of the DispatcherTimer because i have to much freezes and delays in the UI display.

Dispatcher timer code:

timerW = new DispatcherTimer();
    timerW.Tick += new EventHandler(timerW_Tick);
    timerW.Interval = new TimeSpan(0, 0, 5000);
    timerW.Start();



 private void timerW_Tick(object sender, EventArgs e)
        {
            DisplayWegingInfo();
            CaculateTimen();
        }

Code for the System.Threading Timer:

public void InitializeDispatcherTimerW()
    {
        TimerCallback callback = MyTimerCallBack;
        timerW = new Timer(callback);

        timerW.Change(0, 5000);
    }

    private void MyTimerCallBack(object state)
    {
        DisplayWegingInfo();
        CaculateTime();
    }

Thanks.

  • 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-02T00:39:18+00:00Added an answer on June 2, 2026 at 12:39 am

    Judging by the name DisplayWedgingInfo, I would guess this method updates the UI? System.Threading.Timer executes on a thread that is different than the UI thread, so to be able to update the UI from that thread you would need to marshal those calls back to the Dispatcher thread using Dispatcher::[Begin]Invoke.

    So you can leave whatever expensive work that doesn’t touch UI elements as is, but for the UI manipulation you would simply do:

    string someValue = this.SomeExpensiveOperation();
    
    this.Dispatcher.BeginInvoke(
        DispatcherPriority.Background,
        new Action(() => 
       { 
              this.myControl.Text = someValue; 
       }));
    

    I should point out that there will be some interruption to any UI interaction/rendering that might be going on when the invocation does occur. This is unavoidable as the execution will happen on the main thread. By using DispatcherPriority.Background you at least schedule the update with a priority that keeps it lower than any input that the user might be providing at the time. However, don’t expect to be able to make a massive update to the UI without any penalty. If you need to do this it’s best to queue up multiple invocations with Background priority so that they can happen with higher priority stuff like input in between if necessary.

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

Sidebar

Related Questions

I'm converting a open-source application from C to Delphi, but I'm having problems converting
I'm having trouble with a liferay installation that is suddenly (without any code modifications)
I'm having problems converting a binary rooted tree to newick format. The full explanation
I`m having problems converting a char array read from file to an int array.
I have the following SQL that I am having problems converting to HQL. A
I'm having problems converting a wstring to jstring in unix, as the size of
Ive been having some problems regarding circular references when converting EF entities to json
I'm having problems converting HTML into regular expressions. I just can't seem to figure
I'm having problems converting smallint in t-sql to integer in C#. Please can someone
I'm having some problems with converting some JSON and I'm after some help. This

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.