UI not responding when async method is called, only with sfTreeGrid

Hello
Using following code i'm able to cancel getDocuments() method using standard wpf DataGrid and OperationCanceledException is thrown as expected.
When i'm using sfTreeGrid, CommandCancelLoadDocuments button on UserControl won't works, i can click it but cancelLoadDocuments is not raised.
I suppose sfTreeGrid, during its ItemsSource filling, restrain UI thread. However UI is not blocked, i can select Items and scroll the list but i can not stop the loading.

How can i solve the problem?
//UserControl XAML
<sf:SfTreeGrid ItemsSource="{Binding Collection.Documents}"  AutoGenerateColumns="True"/>
<Button Command="{Binding CommandLoadDocuments}">Start Load</Button>
<Button Command="{Binding CommandCancelLoadDocuments}">Stop Load</Button>
//ViewModel
ViewModel()
{
Collection= new Collection();
}
//Action of CommandLoadDocuments
private void loadDocuments(object param)
{
if (Collection != null)
{
   Task.Run(async () => await Collection.AsyncGetDocuments()).ConfigureAwait(false);
}
}
//Action of CommandCancelLoadDocuments
private void cancelLoadDocuments(object param)
{
if (Collection != null)
{
Collection.CancelLoadDocuments();
}            
}
//Collection Class
public ObservableCollection<Tree> Documents { get; set; } = new ObservableCollection<BsonTree>();
public void CancelLoadDocuments()
{
cts.Cancel();            
}
public async Task AsyncGetDocuments()
{
await Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
Documents.Clear();
progressHandler = new Progress<double>(value =>
{
LoadingDocProgress = Math.Round((decimal)value, 1);
});

}));
cts = new CancellationTokenSource();
var cancellationToken = cts.Token;            
if (!cancellationToken.IsCancellationRequested)
{
try
{
getDocuments(cancellationToken);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}

private readonly object _sync = new object();
private void getDocuments(CancellationToken token)
{
int i = 1;
var progress = progressHandler as IProgress<double>;
try
{
lock (_sync)
{
foreach (var item in sourceCollection.FindAll())
{
if (token.IsCancellationRequested)
{
Console.WriteLine("GetDocuments Cancelled");                        
token.ThrowIfCancellationRequested();
}

var doc = new Tree(item); 
doc.GetNode();

Application.Current.Dispatcher.Invoke(() =>
{
Documents.Add(doc);
});

double x = 100 / Count * i;
progress.Report(x);
i++;
}
progress.Report(0);
}
}
catch(Exception ex)
{
if(ex.GetType() == typeof(OperationCanceledException))
{
Console.WriteLine(ex);                    
}
else
{
throw new Exception(ex.Message);
}
}
}

11 Replies 1 reply marked as answer

SS Susmitha Sundar Syncfusion Team June 3, 2020 03:10 AM UTC

Hi Michele, 
 
Thank you for using Syncfusion controls. 
 
Based on your provided information, we have prepared simple sample. When we click the Start Load button it does not works properly. We suspect that we are missing something. Can you please modify the below sample as per your scenario or provide your test sample? 
 
 
It will be helpful for us to check on it and provide you the solution at the earliest.   
 
Regards, 
Susmitha S  



MI Michele June 3, 2020 04:18 PM UTC

Hello Susmitha 
I have modified your Sample and now the program is working

In GridViewControl.xaml i've tested some controls
1 - MS Datagrid
2 - SfTreeGrid
3 - SfDataGrid

        <!--<DataGrid ItemsSource="{Binding Collection.Documents}"/>-->
        <Syncfusion:SfTreeGrid ItemsSource="{Binding Collection.Documents}"/>
        <!--<Syncfusion:SfDataGrid ItemsSource="{Binding Collection.Documents}" />-->

Using 1 and 3 everything works fine
Using SfTreeGrid is not possibile to stop loading documents and performance are very poor

So, how can I stop loading data in SfTreeGrid?
And is it possibile to speed up loading data?

Thanks
Michele

Attachment: SfTreeGrid_OperationCanceledException_2540d61e.zip


SS Susmitha Sundar Syncfusion Team June 5, 2020 03:14 AM UTC

Hi Michele, 
 
Thank you for using Syncfusion controls. 
 
We were able to replicate your reported scenario “UI not respond while loading the items in SfTreeGrid Async mode”. Currently, we are analyzing this. We will check and update you details on or before June 8, 2020. 
 
We appreciate your patience until then.   
   
Regards,   
Susmitha S   



SS Susmitha Sundar Syncfusion Team June 8, 2020 03:31 PM UTC

Hi Michele 
 
Sorry for the inconvenience caused.   
 
Currently, we are analyzing your reported scenario in our source level. We need some more time to check this. We will update you details on or before June 10, 2020. 
 
We appreciate your patience until then. 
 
Regards, 
Susmitha S  



MI Michele June 9, 2020 01:05 PM UTC

Hello
No problem, i can wait

Michele


SS Susmitha Sundar Syncfusion Team June 11, 2020 02:42 AM UTC

Hi Michele,   
   
We regret for the inconvenience caused.    
   
We did not find the exact cause of your reported scenario. Currently, we are working on this. We will check and update you details on or before June 12, 2020.   
   
We appreciate your patience until then.     
     
Regards,     
Susmitha S     



SS Susmitha Sundar Syncfusion Team June 14, 2020 01:18 PM UTC

Hi Michele,    
    
We regret for the inconvenience caused.     
    
We have forwarded this query to our development team. We will check and update you details on or before June 16, 2020.    
    
We appreciate your patience until then.      
      
Regards,      
Susmitha S      



SS Susmitha Sundar Syncfusion Team June 16, 2020 05:33 PM UTC

Hi Michele,   
 
Thank you for your patience. 
 
       We have created bug report for the reported issue“ UI not respond while loading the items in SfTreeGrid Async mode. Can you please confirm your Syncfusion version? We will provide patch or include the fix in our NuGet release based on that version. 
 
You can track the status of this report through the following feedback link,   
 
 
Note: The provided feedback link is private, and you need to login to view this feedback.   
 
Regards, 
Susmitha S 



MI Michele June 20, 2020 08:08 AM UTC

Hello Susmitha
I'm using 18.1460.0.42 version

Regards
Michele


SS Susmitha Sundar Syncfusion Team June 22, 2020 01:02 PM UTC

Hi Michele,    
  
Thank you for the update.  
  
We will fix this issue and will provide patch on June 30, 2020. 
 
We appreciate your patience until then. 
 
  
Regards,  
Susmitha S  



SS Susmitha Sundar Syncfusion Team June 30, 2020 04:24 PM UTC

Hi Michele, 
 
Thank you for your patience. 
 
We have fixed the both issue “UI not respond while loading the items in SfTreeGrid Async mode“. You can download the patch from following location.  
 
   
  v18.1.0.42 
Recommended approach – exe will perform automatic configuration       
Please find the patch setup here:    
     
Advanced approach – use only if you have specific needs and can directly replace existing assemblies for your build environment                        
Please find the patch assemblies alone from: 
   
  
Assembly Version: 18.1.0.42 
Installation Directions:  
This patch should replace the files “Syncfusion.SfGrid.WPF” under the following folder.  
$system drive:\ Files\Syncfusion\Essential Studio\$Version # \precompiledassemblies\$Version#\4.0  
Eg : $system drive:\Program Files\Syncfusion\Essential Studio\ 18.1.0.42\precompiledassemblies\ 18.1.0.42\4.0  
   
To automatically run the Assembly Manager, please check the Run assembly manager checkbox option while installing the patch. If this option is unchecked, the patch will replace the assemblies in precompiled assemblies’ folder only. Then, you will have to manually copy and paste them to the preferred location, or you will have to run the Syncfusion Assembly Manager application (available from the Syncfusion Dashboard, installed as a shortcut in the Application menu) to re-install assemblies.  
   
Note 
To change how you receive bug fixes, ask your license management portal admin to change your project’s patch delivery mode.  
   
   
Disclaimer:  
If you have received other patches for the same version for other products, please apply all patches in the order received. Please note that we have created this patch for version 18.1.0.42 specifically to resolve the following issue reported in the forum 154791.  
 
Regards, 
Susmitha S 


Marked as answer
Loader.
Up arrow icon