简体   繁体   中英

Request input from user before start few threads

private void Home_Load(object sender,EventArgs e){

//request input by user first
getUserInput()

Thread threadA = new Thread(new ThreadStart(threadAtoRun()));
threadA.Start();

Thread threadB = new Thread(new ThreadStart(threadBtoRun()));
threadB.Start();

Thread threadC = new Thread(new ThreadStart(threadCtoRun()));
threadC.Start();

}

private void getUserInput(){
     //request input from user,user need to select and submit to form ,this input from user use      globally for threadA,threadB and threadC. Only request one times before threadA,threadB and threadC run.
}

private void threadAtoRun(){
     //to do something
}

private void threadBtoRun(){
    //to do something
}

private void threadCtoRun(){
    //to do something
}

In this program,required end user input before run few threads,the input would be used by threadA,threadB and threadC. Only request one times while program executed.

How to make this works?

Launch a modal form to get the user input. Modal form will block execution until user submits/cancels the modal form. When the modal form returns, continue processing by starting the threads.

var form = new GetInputForm();
if (DialogResult.OK == form.ShowDialog()) {
  // continue processing, start threads
}

You can check whether input is already collected before launching the form to ensure user is only asked for the input once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM