Any way to cancel a dialog that's already called to showDialog?

G

Guest

Hi, I'm using vs2005, .net 2.0. I have a form with crystal Viewer that I
call as showdialog. I want to give the user an option to cancel out of it is
it's taking too long to process. Is there a way to do this? How can I pop
up another dialog box or message in this dialog form for user to click on a
Cancel button if it's taking to long to display the report?
 
G

Guest

I'm not sure if this would work, but I would try making a public static
variable, and a timer with an interval of like... 20 seconds... and like,
start the timer in the line right before "ShowDialog()" for the crystal
viewer. Then after 20 seconds is passed (in the timer_Tick event method) I
would make it show a dialog box that says "This is taking long, would you
like to cancel?"

when the crystal viewer dialog is shown, I would make the variable equal to
like 1, so if the variable is not equal to 1 when 20 seconds has passed, I
would show the dialog saying that it is taking to long, and stop the timer.

if yes is clicked I would use e.cancel; somewhere.... I'm not sure where...

maybe that wouldnt even work.. just throwing it out there...

hope this helps.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi
roger_27 said:
I'm not sure if this would work, but I would try making a public static
variable, and a timer with an interval of like... 20 seconds... and like,
start the timer in the line right before "ShowDialog()" for the crystal
viewer. Then after 20 seconds is passed (in the timer_Tick event method)
I
would make it show a dialog box that says "This is taking long, would you
like to cancel?"

I do not think this will work, the timer just place an event in the windows
queue but as the form is busy generating the report it's basically blocked
to handle new messages.

honestly I do not see a clean solution to this. the main problem being that
the form will be blocked generating the report. so it will not handle any
event

OP:
Did you look into the archive and in the CR forums?
 
C

Christof Nordiek

Hi Pucca,

the main problem is, to get the processing off the UI-Thread. Otherwise
there is no way to interrupt it.
Since it is the crystal Viewer, it might be impossible, if the control does
the processing in the UI-Thread.
If you put an Button on the Form. Can you click it (and process the
Click-event)? If so, it should be possible to close the form from that
event.
 
G

Guest

Is multi-threading possible way to do this? I haven't done that before but
if yes then I'll start digging information on how to do this using
multi-threading.
 
M

Marc Gravell

Threading (displaying another form on a second UI thread) would allow
you to show a separate UI happily while this blocking UI renders
itself (so the user isn't completely blocked); however, the only real
managed way to close this blocking form is to ask the form to close
itself (thread affinity); to do that, you need to post a message to
the form's queue (Control.Invoke / Control.BeginInvoke). Unfortunately
if this form is truly blocking, then it won't be processing it's
queue, so it will never receive the request to close itself. There may
be some nastier Win32 ways of tearing this form down, but they won't
be pretty. I don't know much about crystal viewer, but have you tried
looking at the docs for ways of interrupting a long running query /
report?

Marc
 

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