Hi. I have a function that needs to be called repeatedly for the entire duration of the program, is there an infinite loop in Cocoa that I can stick this function in? For instance, in Windows, I can write something like
and stick myFunction into the WindowProc.
Basically, WindowProc is called by Windows in an infinite loop to check and dispatch messages. I override this function so it would call my function as well. This way I save myself a thread and I don't need to deal with asynchronous access to my data.
I wonder if there is anything similar in Cocoa. Thanks.
Code:
LRESULT MyWindow::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
myFunction();
// OnWndMsg does most of the work, except for DefWindowProc call
LRESULT lResult = 0;
if (!OnWndMsg(message, wParam, lParam, &lResult))
lResult = DefWindowProc(message, wParam, lParam);
return lResult;
}
and stick myFunction into the WindowProc.
Basically, WindowProc is called by Windows in an infinite loop to check and dispatch messages. I override this function so it would call my function as well. This way I save myself a thread and I don't need to deal with asynchronous access to my data.
I wonder if there is anything similar in Cocoa. Thanks.