Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

sorting - How to create an observableCollection Sortable and multithreading -


here problem , have created sortablecollection : observablecollection , added sort method (sort colors). when sort collection principal thread , works every thing fine , works when try sort customcollection using item in collection have expetion : (the calling thread cannot access object because different thread owns it). have looked in web , found several solution , one solution

this type of solution put collection multithread insertion , removing moving operation. not custom sort. help,

wpf classes have thread affinity. means changes objects must in same thread created. difficult create user interface api thread-safe, microsoft chose keep singlethreaded , force run-time checking make sure of it.

that said, there few options have perform sort in background thread, , apply in ui thread. first option copy sortablecollection plain old list or array , perform sort in background. once background thread complete, use dispatcher execute code in ui thread. every ui element in wpf extends system.windows.threading.dispatcherobject , extend system.windows.freezable. dispatcherobject dispatcher execute code in ui thread.

logically, execution this:

public void backgroundsort() {     list<t> items = new list<t>(this.toarray());     backgroundsortdelegate del = sort;      del.begininvoke(sortcompleted, del); }  private void sortcompleted(iasyncresult result) {     backgroundsortdelegate del = result.asyncstate backgroundsortdelegate;      list<t> items = del.endinvoke(result);     this.dispatcher.invoke(()=>{this.collection = items;}); } 

the short explanation of happened background worker/delegate using copy of items in list. once sort complete, calling dispatcher object , invoking action. in action assigning new sorted list our object.

the key assigning result of background work within ui thread use ui's dispatcher object. there's half dozen ways invoke background worker in c#, approach work in background thread ui thread same.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -