I try to fill a DotNet DataGridView via MultiThreading. It makes Max crash (Max gets totally unresponsive and i have to kill it via task manager). Any help would be awesome!
Problem
If i add more rows (via multithreading) than "fit" (so that a scrollbar has to be created), 3Ds Max crashes. It works if you just execute "addItems()" without any Multithreading.
Try the snipped below. As soon as you comment
out the 3rd "dgv.rows.add()" it works (because no scrollbar has to be created?!).
Alternatives
Might be possible to modify the DataSource of the DatagridView directly via DotNet DataTable but it seems that this doesn't work (except you use a dotNet form instead of a Maxscript Rollout). The DataGridView doesn't show any data/stays gray) - found one thread where a guy tried the same, without success.
Questions
1. Any idea how i can modify (add/remove) the DataGridView without crashing max?
2. Any idea how i can bind a dataTable to the DataGridView in a MaxscriptRollout?
(
rollout dgTest "DataGridView Test" width:448 height:600
(
dotNetControl dgv "System.Windows.Forms.DataGridView" pos:[8,8] width:432 height:110
fn addItems = (
dgv.rows.add()
dgv.rows.add()
--Comment this out to avoid a Max crash
dgv.rows.add()
)
on dgTest open do (
--Create a Column and add it to the DataGridView
infoCol = dotNetObject "System.Windows.Forms.DataGridViewTextBoxColumn"
infoCol.headerText = "Info"
dgv.columns.add infoCol
--Execute the addItems Function via MultiThreading
myThread = dotnetobject "CSharpUtilities.SynchronizingBackgroundWorker"
dotnet.addEventHandler myThread "DoWork" addItems
myThread.runWorkerAsync()
)
)
createDialog dgTest
)
Replies
I'm not sure this is the right place to use multithreading. Even the regular 3ds Max UI is all single threaded.
But if scrollbars are the problem, then just disable them while you fill out the grid.
I use Max 2011 and here Max freezes not only 4 seconds but at least 3 minutes, if not more. BUT, disabling the scrollbars works!!!
Why i use MT:
I crawl through a lot data and already fill the list (single threaded) but then in addition i change the color of the cells and add images to an extra row. This already works and feels really fluent.
My next step is to not clear() the list everytime when somthing changes - i want a background-thread which checks what's in the list and what has to be added/deleted and only that stuff shall be touched - the rest shall stay. I hope this will lead to a good UX feeling
Any Ideas about managing to manipulate and show the Datasource? (was my 2nd question)