The iasyncoperationwithprogress interface definition and its progress attribute definition prototype are as follows:
Generic <typename tresult, typename tprogress> Public interface class iasyncoperationwithprogress: iasyncinfo
Property completion <tresult, tprogress> ^ progress {asyncoperationprogresshandler <tresult, tprogress> ^ get (); void set (asyncoperationprogresshandler <tresult, tprogress> ^ value );}
Public Delegate void asyncoperationprogresshandler (iasyncoperationwithprogress <tresult, tprogress> asyncinfo, tprogress progressinfo)
Example:
void test () {windows: Foundation: iasyncoperationwithprogress
^ async = create_async ([] (progress_reporter
Report) {double N = 12.34; For (INT I = 0; I <10; ++ I) {concurrency:: Wait (1000); N ++ = 1.0; report. report (I + 1) * 10);} return N;}); async-> progress = ref new asyncoperationprogresshandler
([] (iasyncoperationwithprogress
^ op, int Pro) {outputdebugstring (L "Progress:"); outputdebugstring (Pro. tostring ()-> data (); outputdebugstring (L "%... \ n ") ;}); create_task (async ). then ([] (double N) {outputdebugstring (L "result ="); outputdebugstring (N. tostring ()-> data (); outputdebugstring (L "\ n") ;}
output result:
progress: 10%...
progress: 20%...
progress: 30%...
progress: 40%...
progress: 50%...
the thread 0xed4 has exited with code 0 (0x0 ).
progress: 60%...
progress: 70%...
progress: 80%...
progress: 90%...
progress: 100%...
result = 22.34