ShowDialog question

  • Thread starter Richard L Rosenheim
  • Start date
R

Richard L Rosenheim

I would like to detect when a form is invoked as the result of a ShowDialog
call.

Anyone have any ideas or suggestions on how to do that?

TIA,

Richard Rosenheim
 
C

Cor Ligthert

Richard,

Sometimes I see here messages I don't absolutly not understand.
Who is calling the form using a ShowDialog.

However you can always overload the showdialogoperator with me/this.
Which set the parent of the form.

I hope this helps?

Cor
 
R

Richard L Rosenheim

Cor,

Yes, in re-reading it, it probably wasn't my clearest question. I was also
trying not to write a long winded question either (like this one).

As you know, when ShowDialog is invoked, (along with possibly doing other
things), it causes the form to be displayed. Then it waits until
DialogResult is assigned a value, at which point it returns the value to the
parent and exits.

I would like to detect when the form has been displayed, so that while
ShowDialog is waiting for the value of DialogResult to be assigned, my
dialog can do some processing. My processing routine would be displaying
status information, so I don't want the processing to begin before the form
is actually displayed.

So, I can't just do something like this:

Public Overloads Function ShowDialog() As DialogResult
DoProcessing
Return MyBase.ShowDialog()
End Function

Nor, do I know exactly what all ShowDialog does internally, so I don't think
I really want to anything like this:

Public Overloads Function ShowDialog() As DialogResult
Me.Show
DoProcessing
Return MyBase.ShowDialog()
End Function

One possible approach would be to enable a timer, allowing a little time to
elapse (hopefully enough time for the form to display) and then calling the
processing routine.

The approach I'm currently utilizing is to set a flag in the ShowDialog
event, and then having the Activated event invoke the processing routine
when the flag is set. I needed the flag to prevent the Activated event from
invoking the processing routine every time the form gets the focus. And by
initializing the flag in the ShowDialog event, the code will still work if
the same instance of the form ever gets invoked more than once by a call to
ShowDialog.

While this approach seems to work, I'm not sure if it's the proper or best
way of dealing with the problem. Hence, the reason behind my original
question.

Richard Rosenheim
 
C

Cor Ligthert

Richard,

The showdialog is expresly created in this way that there is no processing
done.

What you ask is often thought, however think it again over what you want to
do, you are not the first.

Programming is mostly making a chain of from each other dependend
instructions (althoug that are very much repeated instructions). Although
you see a lot of multithreading in this newsgroup, is my expirience that
when I don't use queues it is in most cases hard to use multithreading on an
efficient way (This expirience is very old)

The route you are taking now, makes that your would do yourself the
synchronization. Probably will that take (to keep that working well) more
time than you need for building your program without that.

When you want it coute a coute, than you can make your own openfiledialog,
that would probably take less time than the path you try to achieve not.

Or as another approach start the process you want to do while the
OpenFileDialog is showed in a seperated thread.

I hope this gives some idea's

Cor
 

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