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# - How to start a thread to keep GUI refreshed? -


i have window button triggers lengthy processing. put processing in separate thread, -- surprise -- makes gui frozen anyway. no control refreshed, cannot move window.

so the question how start thread, won't interfere gui, i.e. gui date (while processing change data, , gui displays pieces of it)?

that how start thread currectly:

        var thread = new thread(dolearn);         thread.isbackground = true;         thread.start(); 

edit 1

jon:

  1. i don't use locks @ all
  2. no join calling
  3. the ui thread left alone -- sits there

the processing big loop math operations, not allocating memory, on ui side have controls binding (wpf) data, number of current iteration of main loop. should refreshed each time main loop "ticks". counter of loop property triggers onpropertychanged each change (classic wpf binding).

edit 2 -- there!

ok, jon hit nail @ head (who surprises? ;-d) -- thank you! problem comes changing counter. when used instead counter, local counter gui refreshed -- mean move windows, but... couldn't see display of counter.

what have here -- wpf gui, such data-binding

<textblock text="{binding path=counter"/> 

and have counter property of course on each change sends event propertychanged. 1 of listeners sure gui.

so, jon answer valid "the answer", design pov not exactly, because if gui part has pull info counter , update display every (let's say) 3 seconds, why use data binding? me such approach invalidates data binding idea.

i could, theoretically, pass processing thread gui dispatcher, , sending in gui thread, , work (i didn't try it) mean tight coupling of non-gui part , gui part.

so far, have no idea how "right" way. best guess far create timerdispatcher not @ gui side inside processing library, , update counter value sending time time (i didn't try yet though).

small remark: have more properties binded actually, isrunning, changed @ beginning , @ end of processing. , changes affect display correctly -- counter change triggers around 3000 notifications in 3-4 seconds. looks jamming problem. did test -- killed data binding partially, notifications sent, gui not "receiving" them -- listening them. in such case gui frozen.

so, still listening advices -- thank advance sharing.

edit 3

the saga continues here:

how processing , keep gui refreshed using databinding?

it should fine is. things may freezing ui:

  • are locking within ui thread, , locking on same lock in other thread?
  • are calling join on thread ui thread?
  • are doing other heavy work in ui thread?

if come short complete program shows problem, i'm sure fix it... should okay.

edit: okay, you've added this:

the counter of loop property triggers onpropertychanged each change (classic wpf binding).

so you're updating property non-ui thread? expect cause problems, because trigger ui changes wrong thread.

i suggest take approach such as:

  • periodically update counter via dispatcher.begininvoke
  • have "ui counter" , "worker counter" - , copy value "worker counter" "ui counter" in ui thread via dispatchertimer, polling it.

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 -