Thursday, 15 January 2015

c# - Changing cursor after task is complete -



c# - Changing cursor after task is complete -

i attempting alter mouse cursor wait before task begins, , arrow when it's completed. however, cursor seems alter 1 other straight away. code:

this.cursor = cursors.wait; dtresults.writexml(savefiledialog.filename); this.cursor = cursors.arrow; messagebox.show("exporting complete!", "complete!", messageboxbutton.ok, messageboximage.information);

any ideas i'm doing wrong?

you performing tasks synchronously. so, message pump never gets wait cursor phone call far user see.

to prepare should asynchronously. can utilize task parallel librarysince on .net 4.0:

this.cursor = cursors.wait //avoid closure problems string filename = savefiledialog.filename //start task of writing xml (it run on next availabled thread) var writexmltask = task.factory.startnew(()=>dtresults.writexml(filename)); //use created task attach action whenever task returns. //making sure utilize current ui thread perform processing writexmltask.continuewith( (previoustask)=>{this.cursor = cursors.arrow;messagebox.show....}, taskscheduler.fromcurrentsynchronizationcontext());

c# .net wpf user-interface cursor

No comments:

Post a Comment