Randomly encountered System.ArgumentOutOfRangeException when many threads change the SfDataGrid.DataSource (ObservableCollection)
2. I use ThreadPool to manage my underlying threads
3. To be able to change the limit of the active threads, I set ThreadPool.SetMaxThreads() to a huge number. Then the limit_of_the_active_threads is set to a much smaller number. I run my own logic to check and do the following things:
- If the active_thread_count exceeds the limit, I stop creating new thread
- Otherwise, I create [limit_of_the_active_threads - active_thread_count] new thread
- private void CheckThread(object callback)
- {
- var thisCheckThread = CreateNewThread(); //add a new item into the ObservableCollection<TaskThread>
- while (_maxThreadCount > GetUsingThreadCount())
- {
- var currentTask = DequeueTask();
- if (currentTask != null)
- {
- // do the task
- }
- Thread.Sleep(1000);
- }
- GC.Collect();
- RemoveThread(thisCheckThread.ThreadId); //remove the corresponding item in ObservableCollection<TaskThread>
- }
Thank you for contacting Syncfsuion support.
Can you please share us below things?
1. Stack trace of the exception details
2. Syncfusion product version
It will help us to investigate further and provide appropriate solution at earlier.
Regards,
Vijayarasan S
Hi Truong Giang,
Thank you for contacting Syncfsuion support.
Can you please share us below things?
1. Stack trace of the exception details
2. Syncfusion product version
It will help us to investigate further and provide appropriate solution at earlier.
Regards,
Vijayarasan S
Thank you for your reply,
Thanks for the update.
https://www.syncfusion.com/support/directtrac/incidents/283496
Regards,
I am facing the same issue. Do you get any solution to this?
Hi Anmol Gupta,
We suspect that the reported problem occurs due to adding and removing the
records continuously to the underlying collection. Based on our control
architecture, painting will be triggered while adding/removing the items to the
DataSource. At some point in your application, the removal of the record is performed
before completing the painting and ensuring the previously added record. In
such case the record count in the view and the items count in the underlying
DataSource will be mismatched. This leads to accessing the record using some
invalid index which causes the ArgumentOutOfRangeException.
However, you can resolve the reported problem by calling SfDataGrid.BeginInit() method before adding/removing an item and called
SfDataGrid.EndInit() method after adding/removing an item from the underlying
collection. This resolves the exception. But it will suspend/resume the
DataGrid process while adding/removing the items. Refer to the below code snippet,
|
// Batch Updates
//Suspends data manipulation operations in View SfDataGrid.BeginInit();
// Add, remove, and update the underlying collection.
//Resumes data manipulation operations and refresh the View. SfDataGrid.EndInit(); |
UG Link: https://help.syncfusion.com/windowsforms/datagrid/databinding#sourcecollectionchanged
Regards,
Vijayarasan S
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
- 5 Replies
- 3 Participants
-
UN Unknown
- Jun 29, 2020 01:24 PM UTC
- May 18, 2023 02:00 PM UTC