I have a program that does thorough computations for millions of records. Sometimes, it runs for more than an hour, sometimes about 30 minutes. During that time the program is not responding or un-clickable. Is there any workaround for this? Like, the loading mouse icon.
Another problem is that if I make two dictionaries as a datasource of datagrid, it’s very slow compared to reading a csv file and putting it in to datagrid. Here’s the algo:
for i = 0 to last record
datarow row = new datarow
put i to row[0]
put names[i] to row[1]
put comments[i] to row[2]
add row to datatable
end for loop
datatable.acceptchanges()
datagridview.datasource = datatable
Note: names[i] and comments[i] are dictionaries. However, if i just read from a csv file with almost the same loop and put it into datatable and make it as datasource of datagridview, it’s faster (about 5-10 minutes compared to 20 minutes of dictionaries). Is there any workaround for that?
I’d use a task to run this in the background. Then your UI thread won’t be locked up while the task is running.
You’ll need to assign the datasource in the UI thread or you’ll get an exception. That is what the TaskScheduler bit will do for you. When the task is done, your continuation will run on the UI thread (Assuming you set the continuation from the UI thread).