Responding To Asynchronous Functions
-
hello guys... how do I respond to an asynchronous function call? Let's say that I have a function (asynchronous, boolean) like this
classObject->Function_Call();
Now I want to do something like this
BOOL bResult = FALSE;
bResult = classObject->Function_Call();
if(bResult)
{
// do something
}
else
// do something elseNow what do I do in this situation as Function_Call() is asynchronous? Thanks for any input.
This world is going to explode due to international politics, SOON.
-
hello guys... how do I respond to an asynchronous function call? Let's say that I have a function (asynchronous, boolean) like this
classObject->Function_Call();
Now I want to do something like this
BOOL bResult = FALSE;
bResult = classObject->Function_Call();
if(bResult)
{
// do something
}
else
// do something elseNow what do I do in this situation as Function_Call() is asynchronous? Thanks for any input.
This world is going to explode due to international politics, SOON.
The short answer is: you cannot do that. When the function is asynchronous you may usually perform a test like that only to know whether the function was called properly (it might fail, for instance, if
classObject
was not properly initialized). To know the result of the actual function execution you should check that a state change happened, but that is specific of the function (for instance asynchrounousI/O Windows API
provideGetOverallappedResult
function) and there is no general way.Veni, vidi, vici.
-
hello guys... how do I respond to an asynchronous function call? Let's say that I have a function (asynchronous, boolean) like this
classObject->Function_Call();
Now I want to do something like this
BOOL bResult = FALSE;
bResult = classObject->Function_Call();
if(bResult)
{
// do something
}
else
// do something elseNow what do I do in this situation as Function_Call() is asynchronous? Thanks for any input.
This world is going to explode due to international politics, SOON.
Let me address this in simpler terms without any context to the OS. When you say "Async" , the control passes through. In your example, there is no point in waiting to check "bResult". Typically an Async function is attached with a callback function - a function pointer to notify when the operation has been completed. Or you'll attach a Windows Handle (windows) so that the Async function can post updates to the function through messages. So you need to figure out how your function_call() is implemented to let the main thread (for example- main()) know the completion of the function.
-
hello guys... how do I respond to an asynchronous function call? Let's say that I have a function (asynchronous, boolean) like this
classObject->Function_Call();
Now I want to do something like this
BOOL bResult = FALSE;
bResult = classObject->Function_Call();
if(bResult)
{
// do something
}
else
// do something elseNow what do I do in this situation as Function_Call() is asynchronous? Thanks for any input.
This world is going to explode due to international politics, SOON.
Sounds like you need a multithreaded application. With one thread set up to wait for the call while another is doing the normal processing. On the other hand it kind of depends on what you mean by asynchronous. Windows message pump is is another example of managing asynchronous events. Cheers, Henryk
-
hello guys... how do I respond to an asynchronous function call? Let's say that I have a function (asynchronous, boolean) like this
classObject->Function_Call();
Now I want to do something like this
BOOL bResult = FALSE;
bResult = classObject->Function_Call();
if(bResult)
{
// do something
}
else
// do something elseNow what do I do in this situation as Function_Call() is asynchronous? Thanks for any input.
This world is going to explode due to international politics, SOON.
Then you have to wait until you get the result and then decide how to continue.
Visit my project: Derivative Calculator