i'm using tasks in c++/cli application manage time consuming operation without freezong ui, replacement backgroundworker.this basic usage:
workarguments ^arguments = gcnew workarguments( //some argument objects contructor parameters ); task::factory->startnew(gcnew action<object^>(this, &myform::dosomework), arguments); void myform::dosomework(object ^arguments) { //doing stuff } so far, good. problem cannot figure out how iprogress interface provide reports of completed work ui. cannot find way declare delegate compatible startnew() gets iprocess object.
the closest thing i've found asyncinfo::run<tprogress> method (func<cancellationtoken, iprogress<tprogress>, task>), althogh i'm not sure intended usae, notevn tried i'm not sure it's porpouse,
should add iprogress instance workarguments class?
use system::progress<t> class, stock implementation iprogress. ever need if want report progress.
it have missing manual, has unpleasant failure modes if don't use correctly. first requirement must create instance of class on ui thread, can't in worker thread. store in field of class before start task worker can use it. necessary can figure out on thread progresschanged event should raised.
and have careful not call report() often. limit no more once every ~50 msec, give or take. calling @ high rate (more 1000 times per second) fire-hose ui thread , cause stop updating ui , responding input. easy avoid when call when reported progress value changes , progress range limited (like 0-100%).
Comments
Post a Comment