How to interrupt a parent method using a cancel button on a dialog?

Hi all,

I hope I explain this clearly and make it easy to follow.

I have a WebContainer in my page. In this WebContainer the user can configure some things and press a button to create a file.

Pressing the button to create the file will launch a WebDialog (placed inside the webcontainer) by calling WebDialog.show. When I call webdialog.show, there are instructions in the shown event of the dialog to build a file, this includes calling one method of the original WebContainer. This method can take several minutes, and that is why I have placed a cancel button in the shown dialog to cancel the file creation process. This way I can press it and activate a flag (boolean property in the dialog) via the action event.

So, a WebContainer opens a dialog. The dialog pops up with a message that says “creating file” and with a cancel button. The dialog.shown event makes some things and executes a method that belongs to the WebContainer. Inside this Method there is mainly a for loop which is creating the file, but is also checking in each iteration on a boolean flag (property of the dialog) to see if the user cancelled, in which case he exits the loop and aborts creating the file. So the idea is that when the user clicks on the cancel button, the action event should activate this flag and the method which creates the file should abort.

However, it didn’t work as I expected. The action event of the cancel button is not fired until the method exits the for loop (file is already created). This is exactly what I want to avoid, I want to interrupt the loop cause I don’t want to wait for it to finish.

I tried using App.DoEvents but didn’t work. I also thought I could probably use threads, but there aren’t any in WebEdition.

What is the way/best practice for doing something like this? Can someone explain me how RS/Xojo works so that this does not work? or point me out where I can read about it?

Thanks!!!

There are Threads in WebEdition. Greg could probably explain this better, but think of each Session running in its own thread, handling each request that comes in for the Session. If your Session thread is bogged down in a long processing method, it isn’t handling new requests that come in, such as the Cancel button. So move this long processing to a new Thread subclass. When a cancel comes in, set a "cancelled property of the Thread subclass instance. If the Thread needs to refer back to the Session, you’ll need to keep track of that yourself.

-Brad

Thanks Brad!

I did not see Threads on the controls list (on RS2012 R2.1) and though it was not supported. I just added a general object in the main WebPage and set Thread as super.

I notice now that on Xojo they are already available in the controls list.

I’ll use this separated thread to run the creation file process (among some others) and see if the cancel button (which should be inside the main thread of each session) works now.

I’ll do that later and post here the results. Thanks again!

It worked!

:slight_smile: