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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:30:25+00:00 2026-05-13T05:30:25+00:00

I am building a WPF application that calls web services and displays the data

  • 0

I am building a WPF application that calls web services and displays the data returned from the service after being broken down and analyzed by my application. The problem that I am facing is with multithreading. One of the API calls is made using a DispatcherTimer every 60 seconds. The issue is that when this event fires, it blocks the UI thread. I have attempted (in all ways that I can think) to update the UI from the background thread using BackgroundWorker and Dispatcher objects (also delegates) and I cannot figure this out. I need an example showing a label on the UI thread being updated by the background thread. Any help with this would be fantastic as I am about to freak out :).

I have looked at the other articles and it is just not making a terrible amount of sense to me. Please, bear with me as I am pretty new to this. Here is an example of what I would like to do. I have a label on the window named lblCase. I call pullData() every 60 seconds and I want to update lblCase with the returned data without blocking the UI.

private void pullData()
{
  //API call goes here...
  lblCase.Content = iCase;
}

public MainWindow()
{
    InitializeComponent();
    DispatcherTimer timer = new DispatcherTimer();
    timer.Tick += new EventHandler(timer_Tick);
    timer.Interval = new TimeSpan(0,0,60);
    timer.Start();
}

private void timer_Tick(object sender, EventArgs e)
{
  pullData();
}
  • 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-05-13T05:30:26+00:00Added an answer on May 13, 2026 at 5:30 am

    Have a look at this question…

    cheers,

    EDIT:

    Joe – not sure if you’re getting any closer to groking this, so I thought I’d try to put together a simple usage of BackgroundWorker to demonstrate how simple and powerful this class is!

    first – in your constructor…

    public MainWindow()
    {
        InitializeComponent();
    
        BackgroundWork worker = new BackgroundWorker();
        worker = new BackgroundWorker();
        worker.DoWork += new DoWorkEventHandler(worker_DoWork);
        worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
    
        System.Timers.Timer t = new System.Timers.Timer(10000); //  10 second intervals
        t.Elapsed += (sender, e) =>
        {
            // Don't try to start the work if it's still busy with the previous run...
            if (!worker.IsBusy)
                worker.RunWorkerAsync(); };
        }
    }
    

    so we have set up something to delegate some work (in the method ‘worker_DoWork’) on a background thread… whatever happends in that method will not impact the UI thread, and it should look something like:

    private void worker_DoWork(object sender, DoWorkEventArgs e)
    {
        // Whatever comes back from the lengthy process, we can put into e.Result
        e.Result = DoMyBigOperation();
    }
    

    Now when this thread completes, it will fire the RunWorkerCompleted event, which we have handled as such:

    private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        // First, handle the case where an exception was thrown.
        if (e.Error != null)
        {
        // handle the System.Exception
            MessageBox.Show(e.Error.Message);
        }
        else if (e.Cancelled)
        {
            // now handle the case where the operation was cancelled... 
            lblCase.Content = "The operation was cancelled";
        }
        else
        {
            // Finally, handle the case where the operation succeeded
            lblCase.Content = e.Result.ToString();
        }
    }
    

    Hope this helps!
    IanR

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

Sidebar

Ask A Question

Stats

  • Questions 328k
  • Answers 328k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I looked a little more at this and have not… May 14, 2026 at 2:05 am
  • Editorial Team
    Editorial Team added an answer You can't. They were introduced in .NET 3.5. I don't… May 14, 2026 at 2:05 am
  • Editorial Team
    Editorial Team added an answer I think you are looking for the ProfileProvider which let's… May 14, 2026 at 2:05 am

Related Questions

I am builing a win application that has user access control against a sql
I would like to add excel spreadsheet functionality to the WPF toolkit datagrid, can
I'm building a single window WPF application In the window is a list items
I am building a WPF application and I want its background to be filled

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.