开发者

Silverlight: stop thread while waiting for user feedback

开发者 https://www.devze.com 2023-01-01 11:10 出处:网络
Is it OK to stop current thread until user click some buttons in Silverlight? E.g. var clicked = false;

Is it OK to stop current thread until user click some buttons in Silverlight? E.g.

var clicked = false;
ShowDialog(EventOnClosed => clicked = 开发者_StackOverflow社区true);
while (!clicked) {};
return;

P.S. I know the right way. I'm just curious if there's a way to stop and then continue Silverlight execution flow.

P.P.S. Just to be more specific. Imagine a project where javascript alert() is used for messages. How do you replace "return Invoke("alert('')")" with Silverlight messageboxes? Do you change all 500 places to use the correct async technique?


No it isn't and you certainly won't want to tie up the CPU like that even if you do.

In Silverlight you really need to get used to programming in an asynchronous way.

void SomeContainingFunc(Action callBack)
{
  ShowDialog(EventOnClosed => callBack()))
} 

Whatever calls that and wants code to continue after the async operation is completed:-

void SomeCaller()
{
  // ... do some intial stuff here
  Action callBack = () =>
  {
    //.. code to happen after async call completed
  }
  SomeContainingFunc(callBack);
}


What you are attempting to do is halt (or more specifically pause) the UI thread - this is not a good idea in any circumstance, especially if you are waiting for the user to click something!

Just do it the "right way".

0

精彩评论

暂无评论...
验证码 换一张
取 消