Reputation: 251
I am making a game for windows 8 as metro application. When I execute the following code without showing message box it is not at all responding. when i show message box the entire code works fine. What is the problem? Can any one help me?
public async void move()
{
Random rand = new Random();
int i = 0;
while (i<5)
{
Anim.Begin();
int n = rand.Next(97, 123);
char ch = (char)n;
textBlock10.Text =textBlock9.Text;
textBlock9.Text = textBlock8.Text;
textBlock8.Text = textBlock7.Text;
textBlock7.Text = textBlock6.Text;
textBlock6.Text = textBlock5.Text;
textBlock5.Text = textBlock4.Text;
textBlock4.Text = textBlock3.Text;
textBlock3.Text = textBlock2.Text;
textBlock2.Text = textBlock1.Text;
textBlock1.Text = textBlock.Text;
textBlock.Text = ch.ToString();
/*MessageDialog msg = new MessageDialog("test");
msg.Commands.Add(new UICommand("ÿes", null, "YES"));
msg.Commands.Add(new UICommand("no", null, "NO"));
var op = await msg.ShowAsync();//Showing the message
if ((string)op.Id == "YES")
this.Frame.Navigate(typeof(MainPage), null);
*/System.Threading.Tasks.Task.Delay(50);
Anim.Stop();
}
}
the above function is used to move data from one point to another point on screen using text blocks. Anim is storyboard that moves these text blocks to their next places. Please help me
Upvotes: 0
Views: 51
Reputation: 1839
Put "await" in front of Task.Delay(50);
await System.Threading.Tasks.Task.Delay(50);
Otherwise you implement an infinite loop and the app is not responsive because you are burning your CPU :-)
Upvotes: 1