Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Responding To Asynchronous Functions

Responding To Asynchronous Functions

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AmbiguousName
    wrote on last edited by
    #1

    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 else

    Now 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.

    CPalliniC T S T 4 Replies Last reply
    0
    • A AmbiguousName

      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 else

      Now 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.

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      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 asynchrounous I/O Windows API provide GetOverallappedResult function) and there is no general way.

      Veni, vidi, vici.

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • A AmbiguousName

        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 else

        Now 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.

        T Offline
        T Offline
        TinyDevices
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • A AmbiguousName

          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 else

          Now 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.

          S Offline
          S Offline
          soaringpilot
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • A AmbiguousName

            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 else

            Now 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.

            T Offline
            T Offline
            TomasRiker2
            wrote on last edited by
            #5

            Then you have to wait until you get the result and then decide how to continue.

            Visit my project: Derivative Calculator

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups