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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:43:20+00:00 2026-06-17T08:43:20+00:00

I have a WPF window with a button that spawns a BackgroundWorker thread to

  • 0

I have a WPF window with a button that spawns a BackgroundWorker thread to create and send an email. While this BackgroundWorker is running, I want to display a user control that displays some message followed by an animated “…”. That animation is run by a timer inside the user control.

Even though my mail sending code is on a BackgroundWorker, the timer in the user control never gets called (well, it does but only when the Backgroundworker is finished, which kinda defeats the purpose…).

Relevant code in the WPF window:

private void button_Send_Click(object sender, RoutedEventArgs e)
{
    busyLabel.Show(); // this should start the animation timer inside the user control

    BackgroundWorker worker = new BackgroundWorker();
    worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
    worker.DoWork += new DoWorkEventHandler(worker_DoWork);
    worker.RunWorkerAsync();      
}

void worker_DoWork(object sender, DoWorkEventArgs e)
{
    this.Dispatcher.Invoke((Action)(() =>
    {      
        string body = textBox_Details.Text;
        body += "User-added addtional information:" + textBox_AdditionalInfo.Text; 

        var smtp = new SmtpClient
        {
            ...
        };

        using (var message = new MailMessage(fromAddress, toAddress)
        {
            Subject = subject,
            Body = body
        })
        {
            smtp.Send(message);
        }
    }));

}

Relevant code in the user control (“BusyLabel”):

public void Show()
{
    tb_Message.Text = Message;
    mTimer = new System.Timers.Timer();
    mTimer.Interval = Interval;
    mTimer.Elapsed += new ElapsedEventHandler(mTimer_Elapsed);
    mTimer.Start();
}

void mTimer_Elapsed(object sender, ElapsedEventArgs e)
{
    this.Dispatcher.Invoke((Action)(() =>
    { 

        int numPeriods = tb_Message.Text.Count(f => f == '.');
        if (numPeriods >= NumPeriods)
        {
            tb_Message.Text = Message;
        }
        else
        {
            tb_Message.Text += '.';
        }         
    }));
}

public void Hide()
{
    mTimer.Stop();
}

Any ideas why it’s locking up?

  • 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-17T08:43:21+00:00Added an answer on June 17, 2026 at 8:43 am

    Using Dispatcher.Invoke in your worker_DoWork method is putting execution back on the UI thread, so you are not really doing the work asynchronously.

    You should be able to just remove that, based on the code you are showing.

    If there are result values that you need to show after the work is complete, put it in the DoWorkEventArgs and you will be able to access it (on the UI thread) in the worker_RunWorkerCompleted handler’s event args.

    A primary reason for using BackgroundWorker is that the marshalling is handled under the covers, so you shouldn’t have to use Dispatcher.Invoke.

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

Sidebar

Related Questions

I am using WPF and C# I have a button that opens a window,
I have a ListView on my WPF window, and I have a button that
I have a WPF window that I want replaced with another user control on
I have a WPF window that is run on a background thread as a
I have a simple WPF window that has 12 buttons on it. I want
This is C# WPF application. I have a Button that close the application. Is
I have a WPF-window, in this you can click a button to see a
I Have a WPF window that have a RadGridView and a Button, My requirement
I have a WPF window, which contains a button called Cancel. Under ordinary circumstances
I have two images on a WPF window that are on top of each

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.