Is expected to get a Cast error when you have a thread on a dialog page in a web app?
A dialog is not a small window. It is just a fancy DIV, another control on the WebPage. You should place threads on the WebPage itself.
Unfortunately this is incorrect. WebDialogs inherit from the same base class as WebPages so technically this is actually a bug. Fixing it is another matter though.
When a control is placed on a subclass of WebView, they need to internally record where they live in the control hierarchy of the view that they are on (with WeakRefs so they don’t leak). The IllegalCastException is actually down in the internal constructor of the WebDialog in a place where we’re trying to cast a WebDialog to a WebPage. Not the same class, but they are related.
If you want to use a Thread within a WebDialog, my suggestion is:
- Use a WebThread, because they inherently know which session they belong to.
- Add the WebThread in code using a Property on the WebDialog and an AddHandler to a method on the dialog for the Run event, like this:
AddHandler MyThread.Run, WeakAddressOf MyThreadRunEvent
Between this and the width and height incorrectly reported, WebDialogs appear to be very badly bugged. Maybe time to give them some love.
It seems that i get same issue if i put a thread in a container control.
So in the end where is the best way to keep those ? even if i use thread or web thread is same thing, i guess they should be in the main web view and to be referenced in the containers.
Can somebody confirm that ?