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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:44:53+00:00 2026-05-23T03:44:53+00:00

Following scenario: In an WPF application the program calls Log.Write to enqueue messages which

  • 0

Following scenario:

In an WPF application the program calls Log.Write to enqueue messages which will be written to different outputs (DB, File) in another thread. The amount of datasets written can vary from small amounts to 50000 or more entries. The user can close the application every time. To ensure all data will be written even though the user tries to close the application on Application.Exit a Log.Dispose function is called from UI Thread. The UI Thread joins the background thread to wait till all data is written. This is happening on Application.Exit.

Now it would be great to show a progress dialog during this process. The problem is, that the progress is not moving with the following code:

// Initialize
Log.CurrentInstance.DisposingProgress += new EventHandler<DisposingEventArgs>(Log_DisposingProgress)

// initialize dialog
// ...
_dialog.Show();

Log.Dispose(); // in this method data is written back, threads closed and so on

protected void SetPercentage(DisposingEventArgs e)
{
    if (e.DisposingCompleted)
        _dialog.Close();

    _dialog.Value = e.Percentage;
 }

 // this function is called by a timer which checks the status of the disposing process
 protected void Log_DisposingProgress(object sender, DisposingEventArgs e)
 {
     _dialog.Dispatcher.Invoke(new Action<DisposingEventArgs>(SetPercentage), e);
 }

I guessed the problem occures because I call Log.Dipose from UI Thread. So I tried to call Log.Dispose with

new Action(Log.Dispose).BeginInvoke(null, null);

This will make the progress bar moving if I call Dispose on an event like a button click and the application is still running. If I call it from Application.Exit I have to prevent the application from closing. I try it with

new Thread(() => { while(_isDisposing) Thread.Sleep(100); }

but the progress bar is still not moving in this case.

I tried to start another UI Thread where the Progress Dialog should be displayed in, but the program will just close. Because the shutdown call will be still handled when I call Dispatcher.Run().

  • 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-23T03:44:53+00:00Added an answer on May 23, 2026 at 3:44 am

    After longer time now, i try it again. The following code does what I wanted to achieve:

    Log.CurrentInstance.DisposingProgress += new EventHandler<DisposingEventArgs>(Log_DisposingProgress);
    
    var thread = new Thread(() =>
    {
        ...
        _dialog.Show();
    
        while (true)
        {
            lock (currentEventArgsLock)
            {
                if (currentEventArgs != null)
                {
                    _dialog.Value = currentEventArgs.Percentage;
    
                    if (currentEventArgs.DisposingCompleted)
                    {
                        _dialog.Close();
                        return;
                    }
                }
            }
    
            Thread.Sleep(20);
        }
    });
    
    
    var thread2 = new Thread(() =>
    {
        Log.Dispose();
    });
    
    thread.Start();
    thread2.Start();
    
    // make sure both threads finished
    thread.Join();
    thread2.Join();
    
    return;
    
    
    /// <summary>
    /// This function is called to notify about progress changes during disposing of Log.
    /// </summary>
    /// <param name="sender">The sender object.</param>
    /// <param name="e">The event arguments</param>
    protected void Log_DisposingProgress(object sender, DisposingEventArgs e)
    {
        lock (currentEventArgsLock)
        {
            currentEventArgs = e;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often encounter the following scenario where I need to offer many different types
I have the following scenario : I’m pushing 100 messages to a queue shared
Imagine having the following scenario: You need to create a system where the Back
I have the following scenario I have a main form as MDI parent and
How would the following scenario best be implemented: There is a standardized user interface
Please consider the following scenario: map(T,S*) & GetMap(); //Forward decleration map(T, S*) T2pS =
What would you suggest for the following scenario: A dozen of developers need to
I want to accomplish the following scenario in Drupal: You have 2 content-types. Lets
How could I best implement the following scenario? I have a Next Period... button
Hi I need some help with the following scenario in php. I have a

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.