Child form controls not displayed when using Show()

E

emzyme20

Hi there,

I have a form that when you click on a button it does some work that
can take a lot of time. I decided to create a new form with a progress
bar that would keep the user updated that the application is actually
doing something.

The problem I have is that none of the other controls (labels, buttons)
on the progress form display until the parent form has finished doing
whatever it was doing. The progress bar on this form does update itself
everytime PerformStep is called though.

This is how I create the form in the button_click():

ProgressDlg dlg = new ProgressDlg();
dlg.Owner = this;
dlg.Show();

The function then continues to do its work and it's not until the end
of processing that the modeless progress dialog actually fully
displays.

I've searched the help and the forums here and can't find an answer.
Can anyone explain what I am doing wrong.

Many thanks,

Emma
 
S

S.M. Altaf [MVP]

This is happening because the first process needs to complete its task
before it displays your child form's controls.
I think you should have a look at the System.Threading namespace so that you
can put them in two separate threads.

HTH
Altaf
 
E

emzyme20

Thanks for the response. I've checked out Thread, Threading and
ThreadPool on the help but with all the different ways of doing this I
am still having problems. Either my dialogs (both of them) hang or I
never see the progress dialog.

I tried this, but this hung both dialogs:

// in main dialog, create the worker thread
ThreadPool.QueueUserWorkItem( new WaitCallback(ThreadProc) );

// Call back function
private void ThreadProc(Object stateInfo)
{
dlg = new ProgressDlg();
dlg.Owner = this;
dlg.Show();
}

I also tried a similar process of creating a thread and assigning a
callback to a ThreadStart but this never displayed my dialog - it just
shows the bar part drawn when it gets incremented...

// Create thread using ThreadStart.
m_backgroundThread = new Thread(new ThreadStart(ThreadProc));
m_backgroundThread.Start();

Thanks again.

Emma
 
G

Guest

When communicating with UI elements across threads, you will need to use the
..Invoke method of one the other threads controls.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top