wpf c# button wait for a button press

后端 未结 1 449
太阳男子
太阳男子 2021-01-29 16:49

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

v         


        
1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-29 17:18

    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;
    }
    

    0 讨论(0)
提交回复
热议问题