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

  • Home
  • SEARCH
  • 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 9020111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:56:06+00:00 2026-06-16T04:56:06+00:00

I’ve an existing WPF application, which has several sections. Every section is a UserControl,

  • 0

I’ve an existing WPF application, which has several sections. Every section is a UserControl, that implements an interface.

The interface specify two methods: void LoadData([...]) and bool UnloadData().

Those method are called by the UI thread, so we need to do our work in backgroundworker if it’s time consuming.

No problems with LoadData since we can update the UI asynchronously. The problem is with UnloadData().

This should return if we can really leave the current view.

This is computed with the current status of data(Saved/modified/Invalid):

  • Saved return true,
  • Invalid asks if you want to stay to save some
    correct data or leave without saving
  • Modified tell you that you can
    either cancel your change(return true), either continue to
    edit(return false), either save you current data(return true)

The problem is with the “Modified -> Save”. This is a time consuming method, so to respect the philosophy of the application, we should run this in a background thread(with a busy indicator).

But if we just launch the thread and go to the next section, it will return “true” to the method call, and we will directly launch the next view.

In my case, loading the next view before our local data is saved can be a problem.

So:

Is there a way to wait on the background thread to finish before returning “true”, WITHOUT blocking the UI?

public bool UnloadData(){
   if(...){
      LaunchMyTimeConsumingMethodWithBackgroundWorker();
      return true;//Only when my time consuming method ends
   }
   //[...]
}

Important EDIT
Maybe I wasn’t clear enought: I know how to use a BackgroundWorker, or TPL. My problem is that the parent class(the one which call the UnloadData()” is a class that I cannot edit(for multiple reasons: It’s in another DLL that will not be reloaded, it already works with 70+ userControls, all in separate projects(dll), loaded by reflection.

This wasn’t my choice, I don’t find it good, but I’ve to deal with it now. I’m mostly looking for way to make my method wait on the return of my method. I’m not sure if it is possible. But I’m looking for a workaround, it will spare me weeks of works.

  • 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-16T04:56:07+00:00Added an answer on June 16, 2026 at 4:56 am

    Ok now I’m excited, because I think I may have discovered something on my own…

    So, what you do is this: You create a DispatcherFrame, push that frame onto the Dispatcher, and in the RunWorkerCompleted you set the Continue of the Frame to false.

    This is the code so far:

    public void Function()
    {
        BackgroundWorker worker = new BackgroundWorker();
        worker.DoWork += TimeConsumingFunction;
        var frame = new DispatcherFrame();
        worker.RunWorkerCompleted += (sender, args) =>
                                         {
                                             frame.Continue = false;
                                         };
        worker.RunWorkerAsync();
        Dispatcher.PushFrame(frame);
    }
    
    private void TimeConsumingFunction(object sender, DoWorkEventArgs doWorkEventArgs)
    {
        Console.WriteLine("Entering");
        for (int i = 0; i < 3; i++)
        {
            Thread.Sleep(1000);
        }
        Console.WriteLine("Exiting");
    }
    
    private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
        Function();
        Console.WriteLine("Returns");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have an array which has BIG numbers and small numbers in it. I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a small JavaScript validation script that validates inputs based on Regex. I

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.