c# - How to Pause without Blocking the UI -


i have click event causes phone vibrate once button clicked. works great, except vibration doesnt stop until close application. give application time complete vibration , continue rest of method, not want block ui @ all. how might accomplish this

mainpage.xaml.cs

void newbutton_click(object sender, eventargs e) {     //button vibration     if (settings.enablevibration.value)  //boolean flag tell whether vibrate or not     {         vibratecontroller.default.start(timespan.frommilliseconds(100));         //place vibration stop here?     }              this.navigationservice.navigate(new uri("/newpage.xaml", urikind.relate));  } 

i have tried vibrationcontroller.default.stop(); eliminates vibration together. there way wait until after vibration has completed navigate new page, or whatever other action method should perform? reccomendations or advice on implementation or other suggestions?

you can use asynchrony prevent blocking ui. rather blocking ui thread need schedule action happen again 100ms now. adding continutation task.delay call can that:

void newbutton_click(object sender, eventargs e) {     action navigate = () =>         this.navigationservice.navigate(new uri("/newpage.xaml", urikind.relate));     if (settings.enablevibration.value)  //boolean flag tell whether vibrate or not     {         vibratecontroller.default.start();         task.delay(100).continuewith(t =>         {             vibrationcontroller.default.stop();             navigate();         });     }     else         navigate(); } 

Comments

Popular posts from this blog

iphone - Three second countdown in cocos2d -

hyperlink - how to do url routing in php -

c - Avoiding Extra Malloc in Linked List (node->next = NULL) -