Threads on WebContainers

The docs say:

That’s a shame as threads cannot be added to a WebContainer. However, my app makes heavy use of containers, dynamically embedding and removing them. Adding the respective threads to the webpage seems counter-intuitive, instantiating them in code and using addHandler just makes more spaghetti code (even more than it already is as I have to use threads and timers/tasks to update the UI [using the Task class from the examples]).

How do you manage threads and containers?

BTW: Both the IDE and the compiler are misbehaving in that case.
The IDE allows to drop a Non-WebControl instance like a thread onto a container and embedds it in the bottom bar.
The compiler displays a misleading message:

The Task class from the examples isn’t required for web applications but are meant for desktop applications.

I get that, though accessing the UI from a thread within a web application is discouraged, too. What would be the way to go in your opinion?

You should still use them. The browser still has to wait for long running processes before anything is sent back and to the user, it looks like your app locked up.

I don’t remember to have seen something about problems generated from task accessing the controls from threads.
Threads a fundamental parts of web applications i.e. new threads are created automatically by the framework as required to manage the application.
You can verify this, for example, if you put a timer in a page: each action event it is managed by a new thread created by the framework.

The problem that I see using threads to update controls it is related to the “no feedback” you get from the browser i.e. you risk to send to much data to the browser when he can’t handle them.
To remedy to this problem I use a timer in the page and in the action event i refresh what it is needed.
Doing so you get an implicit feedback from the browser telling you it is ready to get data.

Right. The reason for using the Task pattern is different on the web, but it’s still a really good idea.

Thank you Greg for confirming my actions.

Best regards

Okay, maybe I should be a little more precise.

Upon request by the user, I do some heavy work in the background (database wise) and then present it to the user. I do not intend to update the UI iteratively but as a whole. Thus I wanted to shift the heavy work into a thread, meanwhile displaying a “please wait” dialog.
Since all commands are getting sent to the browser once, I cannot simply do

  1. show my wait dialog
  2. do the heavy work
  3. push the results to the browser
  4. hide wait dialog

in one method, right? Now I am even more confused…

Okay, got close to desired behaviour.

  1. I show the waiting dialog
  2. I run a webtimer (by resetting, period 1, mode single) that does the heavy work
  3. I close the waiting dialog.

Works once, than never again.

You can even make this generic where you can pass a delegate method(or methods) to this WebDialog so you can reuse it on the fly with anything you need to process :wink:

Oh my… That works like a charm :smiley: THANKS!