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.

C# Multithreading -


lets have event gets fired 10 times per secod

void session_onevent(object sender, customeventargs e) {   //dostuff    dolongoperation(e); } 

i want method dolongoperation(e); processed on seperated thread everytime event gets fired,

i :

new thread(dolongoperation).start(e); 

but have feeling not performance, wanna achieve best performance, the best thing can ?

thanks idvance..

edit:when said long didnt mean opration take more 1 sec maximum dont want event wait time wanna make in seperated thread...

use 1 thread process request, , enqueue work items thread event.

concretely:

  • copy e
  • create list< customeventargs > , insert copy end
  • synchronize access list thread , event

as member objects of class, this:

list< customeventargs > _argsqueue; thread _processor; 

in constructor of class, do:

_argsqueue=new list< customeventargs >(); _processor=new thread(processormethod); 

define processormethod:

void processormethod() {      while (_shouldend)      {          customeventargs e=null;          lock (_argsqueue)          {              if (_argsqueue.count>0)              {                  customeventargs e=_argsqueue[0];                  _argsqueue.removeat(0);              }          }          if (e!=null)           {              dolongoperation(e);          }          else          {              sleep(100);          }      } } 

and in event:

lock (_argsqueue) {     _argsqueue.add(e.clone()); } 

you'll have work out details yourself, example, in form closing or in disposing of object in question, you'll have to:

_shouldend=true; _processor.join(); 

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 -