0

我正在使用 .net framework 4 和 Visual Studio 2010。我正在使用 C++ 表单。我的代码是这样的:

int k = 0;

void writeFunction(int &k){
    ++k;
    textbox1->text = Convert::toString(k);

    //i want to suspend writeFunction in there, until i click the button1 which is on Form1 
    //because i don't want to stop function, it has to wait to click

    //after i clicked the button1 , the program continue to run code here

   writeFunciton(k);
}
4

2 回答 2

0

Can you add more details about your program? What framework are you using to generate the form, and how do button presses interact with your code?

For example, if you're using Qt then you could use signals and slots to link pressing the button with your method. Depending on the framework there might be other appropriate answers.

Generally I would recommend using a threading library to synchronize your code.

于 2012-04-29T20:36:32.660 回答
0

It is not wise to suspend a GUI function..instead of that use operation state variable in your form class such as

enum OperationState 
 {
  os_normal,
  os_pointselection,
  os_event1,...
 }

After you call textbox->=... swicth to selection state and by using this state track mouse states like click after mouseclick check for os_selection state,then continue you duty..

于 2012-04-29T20:36:58.767 回答