Hi,
See the attached Sample.
The form loads recursively the content of “C:\temp” into a TreeView control.
At Application start, all is good. TreeView is populated, and TreeNodes are working properly.
Pressing the button simulates a long running process using Task.Factory.StartNew(() =>{});
A onFinished Event is raised from inside this background Started Task.
This Event is handled in the Form code. When received it will reload the Treeview.
From Sub ‘BackgroundCompleted_Handler’ , The problems are :
If you expand some nodes before pressing the button, you see that the treeview is properly reloaded without generating an error.
If you don’t raise the event from inside the background task it’s behaving properly.
Can you help about what’s wrong with this sample ?
Regards.
Hi Luca,
You wrongly understood the reason for the background process in my sample. It wasn’t intended to load the treeview, but to simulate a background long running process.
But no problem, your explanations and the modifications to the sample allowed me to solve partially the problem. It gives me a working solution, but I have to further investigate and test to develop the final optimal solution.
Your additional comments are more then welcome, even in the case it wouldn’t help me, which isn’t the case, it will help another guy from community.
I didn’t knew about the lazy mode.
Regarding the lazy load, I have the effect that a parent node without items underneath keeps the spinning when it get’s it’s triangle clicked.
I presume setting showloader=false for the clicked node solves this, but in the Buildtree I can’t find a reference to the clicked node. The selectednode is still the previous one.
Thanks for the lightning fast answer you gave to this previous post.
Regards.
The first problem I see is System.Threading.Tasks.Task.Factory.StartNew. This starts a new thread but the new thread knows absolutely nothing about the wisej context so any update to the client is lost. The thread fires immediately onFinished() which ends up in BackgroundCompleted_Handler. The first line is MessageBox.Show() which exists immediately with code DialogResult.Abort because it’s run out of context (or out of bound).
The next call is Init_TreeView() which works but it cannot update the client because it’s being run from an independent thread without having restored the session.
Use Application.StartTask() instead. It starts the task within the session context. Use Application.Update(this) to push the update to the client. When the client is affected by a background thread there is no request/response so the server has to push the updates to the client, or you have to hit refresh on the browser.
Two more comments 🙂
See attached modified sample.
Please login first to submit.