This is a migrated thread and some comments may be shown as answers.

Slow Paste

7 Answers 73 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Christopher Pozza
Top achievements
Rank 1
Christopher Pozza asked on 11 Oct 2010, 06:05 PM
I have a RadGridView that is bound to items that are slow to create.  When many items are pasted into the grid, the UI freezes until all objects are created.

The slowness of the creation comes from database lookups and calculations.

Is there any way I can handle the creation of the objects by hand?  I would like to use a separate thread.

Thanks!

7 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 11 Oct 2010, 06:18 PM
Hello Chris Pozza,

 It is impossible to perform pasting on another thread. However, what you can do is handle the Pasting event, cancel it, parse the clipboard input yourself, calculate how many items you need to add, perform your time-consuming operations on another thread and once that's done use the RadGridViewCommands.Paste RoutedCommand to trigger pasting once more. This time the GridView will only replace the values in your existing data items and not create new data items as there are enough rows.

Sincerely yours,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Christopher Pozza
Top achievements
Rank 1
answered on 12 Oct 2010, 02:33 PM
I did something similar.  I used System.Threading.ThreadPool.QueueUserWorkItem   to do the expensive part of the creation.  The paste itself (if I comment out the epensive part) takes about 12 seconds for a 1,000 items.  During this time the UI is locked up and unresponsive. 

I have tried putting code at the beginning of the _Pasting event to update the UI (label, cursor, etc...) to show that there is work being done, but the code does not function until after the Pasting event is complete.     


Here is my class, its nothing special:

 

 

public class Item_Branch_Vendor_Holder : INotifyPropertyChanged

 

{

#region

 

 

Instantiation

 

 

 

public Item_Branch_Vendor_Holder()

 

{

}

 

 

public Item_Branch_Vendor_Holder(bool DoCurrentCalc)

 

{

CalculateCurrent = DoCurrentCalc;

}

#endregion

#region

 

 

On Changed Events

 

 

 

public virtual void OnPropertyChanged(string propertyName)

 

{

 

 

if (PropertyChanged != null)

 

PropertyChanged(

 

this, new PropertyChangedEventArgs(propertyName));

 

}

 

 

public event PropertyChangedEventHandler PropertyChanged;

 

#endregion

#region

 

 

Private Vriables

 

 

 

private bool CalculateCurrent = true;

 

#endregion

#region

 

 

Properties

 

 

 

bool _blChanged = false;

 

 

 

public bool HasChanged

 

{

 

 

get { return _blChanged; }

 

 

 

set { _blChanged = value; }

 

}

 

 

string _AutoNum = Guid.NewGuid().ToString();

 

 

 

public string AutoNum

 

{

 

 

get { return _AutoNum; }

 

 

 

set { _AutoNum = value; }

 

}

 

 

bool _LoadedFromDb = false;

 

 

 

public bool LoadedFromDb

 

{

 

 

get { return _LoadedFromDb; }

 

 

 

set { _LoadedFromDb = value; }

 

}

 

 

decimal? _Cost = null;

 

 

 

public decimal? Cost

 

{

 

 

get { return _Cost; }

 

 

 

set

 

{

_blChanged =

 

true;

 

_Cost =

 

value;

 

 

 

if (CalculateCurrent)

 

{

System.Threading.

 

ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(Item_Branch_Vendor.GetCurrentValues), this);

 

}

 

 

else

 

OnPropertyChanged(

 

"PercentChange");

 

}

}

 

 

decimal? _CurrentCost = null;

 

 

 

public decimal? CurrentCost

 

{

 

 

get { return _CurrentCost; }

 

 

 

set { _blChanged = true; _CurrentCost = value; }

 

}

 

 

int? _Leadtime = null;

 

 

 

public int? Leadtime

 

{

 

 

get { return _Leadtime; }

 

 

 

set { _blChanged = true; _Leadtime = value; }

 

}

 

 

string _ItemNum = String.Empty;

 

 

 

public string ItemNum

 

{

 

 

get { return _ItemNum; }

 

 

 

set { _blChanged = true; _ItemNum = value; }

 

}

 

 

int? _MinOrder = null;

 

 

 

public int? MinOrder

 

{

 

 

get { return _MinOrder; }

 

 

 

set { _blChanged = true; _MinOrder = value; }

 

}

 

 

int? _MaxOrder = null;

 

 

 

public int? MaxOrder

 

{

 

 

get { return _MaxOrder; }

 

 

 

set { _blChanged = true; _MaxOrder = value; }

 

}

 

 

bool? _IsPrimary = null;

 

 

 

public bool? IsPrimary

 

{

 

 

get { return _IsPrimary; }

 

 

 

set { _blChanged = true; _IsPrimary = value; }

 

}

 

 

int? _BranchId = null;

 

 

 

public int? BranchId

 

{

 

 

get { return _BranchId; }

 

 

 

set { _blChanged = true; _BranchId = value; }

 

}

 

 

string _PoNotes;

 

 

 

public string PoNotes

 

{

 

 

get { return _PoNotes; }

 

 

 

set { _blChanged = true; _PoNotes = value; }

 

}

 

 

 

public string ItemDesc { get; set; }

 

 

 

public string ItemUnitMeasure { get; set; }

 

 

 

public DateTime? DateModified { get; set; }

 

 

 

public DateTime? LastCostChange { get; set; }

 

 

 

private bool _Processed = false;

 

 

 

public bool Processed

 

{

 

 

get { return _Processed; }

 

 

 

set { _Processed = value; }

 

}

 

 

public decimal? PercentChange

 

{

 

 

get

 

{

 

 

decimal? Percent = null;

 

 

 

if (this.CurrentCost.HasValue && this.Cost.HasValue && this.CurrentCost.Value > 0)

 

{

Percent = 1 - (Cost.Value/CurrentCost.Value);

}

 

 

return Percent;

 

}

}

#endregion

}

Any ideas?

Thanks!

0
Yavor Georgiev
Telerik team
answered on 12 Oct 2010, 02:42 PM
Hello Chris Pozza,

 The pasting operation is executed on the same thread, there is no other way, so the UI is blocked. Your best bet would be to follow my previous suggestion - cancel the Pasting event, calculate how many items you need to add and add them to your collection from another thread. Once you have added them, re-trigger the Paste operation from RadGridViewCommands.Paste. This way pasting won't execute any of your data item creation logic.

Greetings,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Christopher Pozza
Top achievements
Rank 1
answered on 12 Oct 2010, 05:47 PM
I understand what you are saying, but even if I take out the code that causes the slow creation, it takes more than 12 seconds to paste ~1000 items?

Is this normal?
0
Yavor Georgiev
Telerik team
answered on 12 Oct 2010, 05:50 PM
Hello Chris Pozza,

 We have not performed benchmarks of such magnitude, so I'm unable to say. We will try to learn more about this case and let you know.

Best wishes,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Christopher Pozza
Top achievements
Rank 1
answered on 14 Oct 2010, 08:26 PM
Any feedback yet?

I'd love to be able to paste asynchronously.  <:-)
0
Yavor Georgiev
Telerik team
answered on 15 Oct 2010, 11:59 AM
Hello Chris Pozza,

 We have determined that the RadGridView's data engine takes the bulk of the time when pasting such a large number of items into an empty grid. I have created a PITS entry that details a proposal to allow users to create the needed items on their own, rather than going through the data engine. You can vote for it here.

All the best,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Christopher Pozza
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Christopher Pozza
Top achievements
Rank 1
Share this question
or