How to force the server to update the client any time you wish

Hi,

I know the title is strange, but stay with me

as we all know, or as some will learn, Web app are a different beast. The display is not updated until the last return is hit, only then will the server push changes to the client.

My problem is this one: when an operation may take some time, I wish to display a Progress Wheel, in fact a Progress Wheel inside a WebDialog, when the process starts and then hide the WebDialog when the process ends. Sometimes I find a way to achieve this: on the MouseDown event I have the WebDialog show, and at the end of the Action event I hide it.

But I have case where I can’t find a solution. There is modal WebDialog displayed: the user sets some values and hit OK button. The pseudo code is:

' Validate inputs from the user
<...>
' Validation was Ok

' <- this is where I wish to have my WebDialog with the Progress Wheel to be shown

Call some Methods

Hide the Web Dialog

return

There is a method I call to show the Progress Wheel dialog, but if I call it here, it won’t get displayed until return is hit - in fact it won’t show at all.

How can I have the Progress Wheel Dialog be shown ? Hence the title of this question !

Thanks

A WebTimer might help here. It can communicate with the server periodically and be used to hide the progress dialog when your code has finished running.

This is the idea:

  1. WebTimer on page has code in its Action event to close dialog if a property is set to true.
  2. Show your dialog.
  3. Start your code.
  4. In code, set property to True when it has finished so that Timer then closes the dialog.

We use three timers.

Timer 1 shows the progress wheel and fires timer 2
Timer 2 Execute code that takes too much time and then fires timer 3
Timer 3 Hides the progresswheel

Thanks Paul for your suggestion.

There are a couple of things I don’t get.

A WebDialog might help here. Does that mean I would need another WebDialog ?

At point no 2, you say Show your dialog. If I call a method to show the dialog from the action event of the button, the dialog will not show up because the final return was not hit ?!?

Jay, hiding the Progress Wheel is not an issue. The issue is having the Progress Wheel to display. But your suggestion is interesting.

I meant a “WebTimer” might help here. I’ve corrected the original post.

I’m not sure what you mean by “final return was not hit”. You can show your dialog with the progress wheel whenever you want.

John’s suggestion to use another Timer to start your code might also be a good option.

@Paul Lefebvre [quote]
I’m not sure what you mean by “final return was not hit”. You can show your dialog with the progress wheel whenever you want.[/quote]

If from a method - called say GenerateReport - I call another method that show the ProgressWheel Dialog - or display that dialog directly - then call a few more methods and finally hide the ProgressWheel dialog. It’s not until the return inside GenerateReport (the final return) is hit that the client will be updated. That’s the way I understand it, but I may be wrong.

Out of curiosity, do you have ancestors from the Province of Québec - I guess from your last name ?

Yes, you are correct. You can use another Timer to start your methods or go with Threading.

Another explanation is in order here. In your code example:

' Validate inputs from the user
<...>
' Validation was Ok

' <- this is where I wish to have my WebDialog with the Progress Wheel to be shown

Call some Methods

Hide the Web Dialog

return

You are making an assumption that each line of code is being executed and data is being send to the browser. That’s not how web apps work.

In reality, all of the code in that event/method and any methods it calls are executed in its entirety and then any commands generated by that code are sent to the browser, all at once. In reality what you get is:

[code]// validate response

// Show dialog code is queued

// Call some methods

// Hide dialog code is queued

// Queue is sent to the browser[/code]
The result is that the user probably never sees your dialog.

@Paul Lefebvre I used two timers: one to have my WaitDialog with the ProgressWheel and a second one to wait a maximum of time for the process to end normally or declare an issue. That works quite well.

@Greg O’Lone I don’t assume that each line of code change the client immediately. I know that client refresh is delayed till the end of the process. In my code snippet:

' <- this is where I wish to have my WebDialog with the Progress Wheel to be shown

Meant this is where (when) I need to have my ProgressWheel displayed. So I asked for a way to achieve this, and a timer was the answer.