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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:06:23+00:00 2026-05-13T15:06:23+00:00

Here is my scenario: I have a Main ParentWindow . Before opening the parent

  • 0

Here is my scenario:
I have a Main ParentWindow .
Before opening the parent i would like to open a progressWindow and fetch the data from DB displaying this window.
After the data fetch is complete i would like to close the progressWindow by using a delegate and i am running into threading issues.
Just wondering if you have any suggestions:


Here is the code for ParentWindow:


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Shapes;

namespace RounderProgressBar
{

/// <summary>
/// Interaction logic for Window2.xaml
/// </summary>

public partial class ParentWindow : Window
{

    public ParentWindow()
    {
        InitializeComponent();

        progress = new ProgressWindow();
        progress.publisher = this.Subscriber;
        progress.ShowDialog();
    }
    ProgressWindow progress;// = new Window1();
    protected EventHandlerWithParms _subscriber;
    protected EventHandlerWithParms Subscriber
    {
        get
        {
            if (_subscriber == null)
            {
                _subscriber = new EventHandlerWithParms(Execute);
            }
            return _subscriber;
        }
    }
    private void Execute(object sender, EventArgs e)
     {
        (sender as Window).Close();//.Dispatcher.Invoke(Subscriber,null);//.InvokeShutdown();//.Close();

        //progress.Close();
        //this.Close();
        //Window w = new Window();
        //w.ShowDialog();
    }
}

}


Here is the child or progressWindow:


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

using System.ComponentModel;

using System.Collections;

namespace RounderProgressBar
{

/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>

public partial class ProgressWindow : Window

{

    public ProgressWindow()

    {

        InitializeComponent();

        StartWorker(null, null);
    }

    private BackgroundWorker _worker;

    private void StartWorker(object sender, RoutedEventArgs e)
    {
        _worker = new BackgroundWorker();
        _worker.WorkerReportsProgress = true;
        _worker.WorkerSupportsCancellation = true;

        _worker.DoWork += delegate(object s, DoWorkEventArgs args)
        {
            BackgroundWorker worker = s as BackgroundWorker;
            //for (int i = 0; i < 10; i++)
            //{
            if (worker.CancellationPending)
            {
                args.Cancel = true;
                return;
            }

            //System.Threading.Thread.Sleep(1000);
            runInBack();
            //int max = int.Parse((_progressBar.Maximum - 1).ToString());

            //If we comment this it will go into infinite loop as completed will never get triggered
            //worker.ReportProgress(/*max*/9);//worker.ReportProgress(9);//worker.ReportProgress(i + 1);
            worker.ReportProgress(9);
            //}
        };

        _worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
        {
            //_progressBar.Value = args.ProgressPercentage;
        };

        _worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
        {
            //_btnStart.IsEnabled = true;
            //_btnCancel.IsEnabled = false;
            //_progressBar.Value = 0;
        };

        _worker.RunWorkerAsync();
        //_btnStart.IsEnabled = false;
        //_btnCancel.IsEnabled = true;
    }
    private void runInBack()
    {
        System.Threading.Thread.Sleep(3000);
        //IsBusExecuted = true;
        if (this.publisher != null)
            publisher(this, null);
    }
    public EventHandlerWithParms publisher;
    private void CancelWorker(object sender, RoutedEventArgs e)
    {
        _worker.CancelAsync();
    }

    private bool IsBusExecuted = false;
    void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        if (IsBusExecuted)
        {
            t.Stop();
            MessageBox.Show("1");
            this.rpb.Stop();
        }

    }

    private void Execute(object sender, EventArgs e)
    {
        this.Close();
    }

    private System.Timers.Timer t = new System.Timers.Timer(1000);
}
public delegate void EventHandlerWithParms(object sender, EventArgsWithParms e);
public class EventArgsWithParms : EventArgs
{
    public EventArgsWithParms()
    {
    }
    public Hashtable ParmTable = new Hashtable();
}

}

  • 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-13T15:06:24+00:00Added an answer on May 13, 2026 at 3:06 pm

    First of all, calling ShowDialog in InitiallizeComponents method will block UI and not very good solution; No events will be forwarded to GUI thread and that’s why it will never close. Close() method of child form must call its own close when tasks are finished;

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

Sidebar

Related Questions

Here's my scenario - I have an SSIS job that depends on another prior
Here's the scenario: You have a Windows server that users remotely connect to via
Here's the scenario: I have a textbox and a button on a web page.
Here's the scenario: You have an ASP.Net application supported by a Microsoft SQL Server
Here's the scenario I have a Grid with some TextBlock controls, each in a
Here's my scenario: I have a page containing several links; each link is meant
Here's the scenario: I have a set of buttons that I want to bind
Here is the scenario: I have two asp pages. a.aspx is layout and b.aspx
Here's my scenario: I have a simple stored procedure that removes a specific set
Here's the scenario: We have users login on a secure connection. Could an unathorized

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.