wpf c# button wait for a button press

2019-03-07 08:05发布

Ok i'm begginer at coding

So what i'm trying to do is button who gonna wait for
the user to click on one of the multiple other button to continue

void Mainbutton()
{  

    //the program run throw so method  

    //Wait for the user to choose one  button (I made a numeric pad with buttons)  

    //Then use this information to work

}

I know my english isnt that good Thanks a lot

1条回答
劳资没心,怎么记你
2楼-- · 2019-03-07 09:03

Try something like this:

bool gotResponse = false;
//you need to run MainTask in a different thread
Thread thread = new Thread(new ThreadStart(DoWork));
thread.Start();

void DoWork()
{
     //do some work
     //when something else needed from user then popup message
     MessageBox.Show("say whatever you need to say");
     while(!gotResponse)
     {
          //note: this loop doesn't stop until gotResponse = true; 
     }
     //do rest of your work
}

private button_Click(object sender, RoutedEventArgs e)
{
     gotResponse = true;
}
查看更多
登录 后发表回答