Home > Software engineering >  MFC OnTimer () be destroyed after how to automatically perform the following statement
MFC OnTimer () be destroyed after how to automatically perform the following statement

Time:10-11

Pseudo code is as follows:
Want to ask next OnButton1 inside, what method can guarantee the Start () after the statement execution (i.e., OnTimer destroyed after) to run automatically the next statement GetSomething (); ?
To the great god answers, the younger brother first thanks
 void CXXX: : OnButton1 
{
Start ().

GetSomething ();
}

 void CXXX: : Start () 
{

The SetTimer (1, 50, NULL);

}

 void CXXX: : OnTimer (UINT_PTR nIDEvent) 
{
The Switch (nIDEvent)
{
Case 1:
Int FLG.
FLG=0;
FLG=XXXXXXXXX.
if(! FLG)
{
KillTime (1);
}
break;
}
CDialog: : OnTimer (nIDEvent);
}

CodePudding user response:

Many methods:
1. Direct call after KillTime GetSomething ();
2. The KillTimer PostMessage to the main frame, by the main frame call GetSomething ();
3. Put the OnButton1 function to thread,
Thread_xxx ()
{
Start ().
Wait...//wait event
GetSomething ();
}
Killtimer SentEvent notice after thread

CodePudding user response:


Don't have any way, because the program is sequential execution!
In OnButton1 function, the application performed Start function, then executes GetSomething function,
No problem as long as you write function, but your function has a lot of problems, I give you said a!!!!
Your Start function have a problem? You should call SetTimer function directly!

CodePudding user response:

You can do you again after killtimer processing

CodePudding user response:

You the function of writing itself is wrong, click on the button after execution order is
1, enter OnBotton1 ()
2, enter the start ()
3, implement the settimer (), just start the timer, timer didn't execute the commands in, start the time
4, GetSomething (); To perform this,
5, after the start timing 50 ms, execute the command inside the timer,

CodePudding user response:

You can use a Boolean variable to control the
Add member variables to
BOOL m_Exit=false;

In the OnTimer
if(! FLG)
{
KillTime (1);
M_Exit=TRUE;
}
//in OnButton1
Void CXXX: : OnButton1
{
Start ().
While (m_Exit==FALSE)
{
}
GetSomething ();
}

CodePudding user response:

Time consuming process of code, it is best to thread, want to a few seconds pause a few seconds.
You'd better don't do that in the UI thread.
You want to is there a way to realize the function of, because in the embedded development may often use this way. Because of the absence of multithreading, requires a time-consuming function can shard.
And you want you need to do so.
Add member variables, save execution status.
Was first called OnButton1 (click on the button), he only let member variable control execution Start, and then after the timer called OnButton1 (timer in manual calls), a member variable control it only performs the DoSomething ()

CodePudding user response:

You can put your GetSomething (); On the OnTimer () function.

CodePudding user response:

You can't do this, you should:
1, for the direct start timer SetTimer (1, 50, NULL);
2, start don't
3, directly in the OnTimer GetSomething inside () ();

CodePudding user response:

The question is not clear,
Start () statement execution completed Timer destruction is two different things,

CodePudding user response:

Start moment was finished, the get something executes, the timer is not performed,
  • Related