1 intProgressrate =0;2 3 Private Async voidBtnprogress_click (Objectsender, EventArgs e)4 {5Progressrate =0;6 7 varProgress =Newprogress<int>();8 9 //progress changes in progressTenProgress. ProgressChanged + = (obj1, obj2) = One { A if(Progressrate <= -) - { - This. lblprogress.content = progressrate.tostring () +"%"; the This. Pbprogress.value =progressrate; - } - Else - { + This. btnprogress.isenabled =true; - } + A }; at - This. btnprogress.isenabled =false; - awaitReportprogressasync (progress); - } - - //in this report progress progress, change the value of Progressrate in Private AsyncTask Reportprogressasync (iprogress<int> progress =NULL) - { to while(Progressrate <= -) + { - if(Progress! =NULL) the { * awaitTask.delay (Timespan.frommilliseconds ( -)); $Progress. Report (progressrate++);Panax Notoginseng } - } the}
Results:
[C #] C # Concurrent Programming-Asynchronous programming Fundamentals-reporting progress