UI freeze in for loop Need Async and await

  • Thread starter Thread starter ID GO
  • Start date Start date
I

ID GO

Guest
private void CopyData()
{
if (Collection.SelectedCells == null) return;
var sb = new StringBuilder();
var i = 0;
var j = 0;
var controlList = new List<int>();
foreach (var variable in Collection.SelectedCells)
{
controlList.Add(variable.Column.DisplayIndex);
if (controlList.Count == controlList.Distinct().Count()) continue;
i = controlList.Count - 1;
controlList.Clear();
break;
}

foreach (var variable in Collection.SelectedCells)
{
if (j == i)
{
sb.AppendLine(null);
j = 0;
}
switch (variable.Column.Header.ToString())
{
case "Drug":
sb.Append(((Model) variable.Item).Drug).Append("\t");
break;
case "Dosage":
sb.Append(((Model) variable.Item).Dosage).Append("\t");
break;
case "Patient":
sb.Append(((Model) variable.Item).Patient).Append("\t");
break;
case "Date":
sb.Append(((Model) variable.Item).Date).Append("\t");
break;
default:
break;
}
j++;
}
Clipboard.SetText(sb.ToString(), TextDataFormat.Text);
sb.Clear();
}

Datagrid Freeze while Running the above Code...

Collection.SelectedCells is IList<DataGridCellInfo>

Need async and await

Continue reading...
 
Back
Top