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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:47:39+00:00 2026-05-27T13:47:39+00:00

I have a background worker process that starts provisioning a new client for our

  • 0

I have a background worker process that starts provisioning a new client for our system. Here is what the DoWork method looks like:

ProvisioningManager manager = new ProvisioningManager(false)
{
};

System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
    this.MaxSteps = manager.MaxProgress;
}));

manager.StatusUpdated += new ProvisioningManager.StatusUpdatedHandler(manager_StatusUpdated);
manager.TaskCompleted += new ProvisioningManager.TaskCompleteHandler(manager_TaskCompleted);

manager.ProvisionClient();
while (!manager.Completed)
{
    System.Threading.Thread.Sleep(100 * 60);
}

Basically it creates the manager that handles talking to the different sub-systems which provision the client.

Now I have a status update event and completed event for the provisioning manager. When the TaskCompleted event fires I want to be able to set a property on my display object so that the finish button in the wizard is enabled:

void manager_TaskCompleted(object sender, ProvisioningManager.Task taskType)
{
    System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
    {
        this.ProvisioningComplete = true;
    }));
}

The XAML for the button looks like this:

<wizard:WizardPage Header="Provisioning Client..."
                               ShowBack="False" 
                               AllowBack="False" 
                               AllowFinish="{Binding Source={StaticResource ResourceKey=dataObject}, Path=ProvisioningComplete}" 
                               Loaded="Provisioning_Loaded">
</wizard:WizardPage>

This isn’t working. Even though I make sure to hit the dispatcher thread to set the property of the display object it doesn’t actually change the button to enabled until I click on the window. Is this a bug in AvalonWizard or am I not on the correct thread to set an INotifyPropertyChanged? Is there a way to hack this; basically can I programmatically focus the window without the mouse click?

I tired placing that while loop in the DoWork method so that I could use the BackgroundWorker’s completed method:

void provisioningWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
    {
        this.ProvisioningComplete = true;
    }));
}

That doesn’t work either. What gives?!

Update
Here is the requested static resource instantiation for the display object:

<Window.Resources>
    <ObjectDataProvider x:Key="dataObject" ObjectType="{x:Type winDO:NewClientWizardDO}" />
</Window.Resources>

Update II
Here is the property and property change firer:

public bool ProvisioningComplete
{
    get { return this._ProvisioningComplete; }
    set
    {
        this._ProvisioningComplete = value;
        this.NotifyPropertyChanged("ProvisioningComplete");
    }
}

protected void NotifyPropertyChanged(params string[] propertyNames)
{
    if (this.PropertyChanged != null)
    {
        foreach (string propertyName in propertyNames)
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}
  • 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-27T13:47:39+00:00Added an answer on May 27, 2026 at 1:47 pm

    So I couldn’t find out exactly why I was having this issue. I tried setting focus to the window, the button, etc. I tried multiple ways of letting the view know the viewmodel had updated. Basically every suggestion I could find on the web didn’t work. It almost seems like a bug.

    A smarty on my team suggested faking a mouse click on the window. His idea was that since all it took to activate the button was a simple mouse click on the screen then faking one should have the same effect. I thought (and think) that this hack was ridiculous. I did try it out just to see if I could call it a “solution”.

    Well, it worked. We had this same problem in another one of our wizards (not AvalonWizard but a homegrown one). I think there has to be some underlying issue with the way the window redraws after a background thread updates objects that are bound to the UI.

    Anyhow, the way I found to solve this issue is with the following hack-tastic code.

    //import user32.dll and setup the use of the mouse_event method
    [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    
    /// <summary>
    /// Watches for properties to change on the data object, mainly the ProvisioningComplete method
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void DataObject_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
        switch (e.PropertyName)
        {
            case "ProvisioningComplete":
                //if the provisioning is completed then we need to make the finish button selectable.
                if (this.DataObject.ProvisioningComplete)
                {
                    System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
                    {
                        //give the window focus
                        this.Focus();
                        //update the layout
                        WizardPageProvisioningClient.UpdateLayout();
                        //fake mouse click 50 pixels into the window
                        mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, (uint)(this.Left + 50), (uint)(this.Top + 50), 0, 0);
                    }));
                }
                break;
        }
    }
    

    I’ve tested this when the window is not the active window and when the user leaves the window as selected. The focus method seems to take care of this issue when the window isn’t active. Our QA team hasn’t run a complete test against the UI so I can’t say if there is any situations where it doesn’t work, but it seems to be the best solution that I’ve come up with to date.

    I’m open to any other suggestions if anyone out there has a better idea of what could be causing the button to not update.

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

Sidebar

Related Questions

In my rails application, I have a background process runner, model name Worker, that
I have a background worker that stops after 100 iterations. Like this: BackgroundWorker bgWorker
lets say i have a background worker in a class that perform db query
Scenario I have a background worker in my application that runs off and does
Background We have worker processes that read jobs from a table in SqlServer then
I have a background worker running a long database task. i want to show
I have a background worker which can be cancelled. The normal flows interrupt itself
Hi all I have a BAckground worker and a Datatable. I have a timer
Hi all i have a background worker thread and some unmanaged code dlls ,
Background I have a Spring batch program that reads a file (example file 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.