Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
SQL
 public void computeABC()
        {
           /*this is dummy code  , computeA(),computeB(),computeC() needs to be called asynchronously  the result of this fuctions will be input to computeResult() */


            objMyClassA = computeA(); //
            objMyClassB = computeB();
            objMyClassC = computeC();

            computeResult(objMyClassA, objMyClassB, objMyClassC);

        }

public MyClassA  computeA ()
{

     /* database call */
}
public MyClassB  computeB ()
{

    /* database call */
}
public MyClassC  computeC ()
{

    /*database call */
}
Posted
Updated 24-Feb-15 17:49pm
v2
Comments
Sergey Alexandrovich Kryukov 24-Feb-15 23:35pm    
Asynchronous relative to what? Each other, something else? why?
—SA
mahadevkarekar 24-Feb-15 23:42pm    
As seen in code i have 3 methods . computeA() ,computeB() ,computeC(). all this 3 methods perform heavy database operations. so i need to call all this 3 method at one time.
Sergey Alexandrovich Kryukov 25-Feb-15 6:35am    
It explains why would you need to call them in parallel to, say, main thread, UI thread, but it does not explain "one time". You could call them in sequence.
—SA

1 solution

You should launch a new Thread for every function and use a Semaphore or an AutoResetEvent to let the main thread awaiting for code completion.

There is an example here: MSDN AutoResetEvent
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Feb-15 6:37am    
All right, do it. Or use a separate thread. Only don't listen to this "answer".
—SA
Joan Magnet 25-Feb-15 7:44am    
Well, look at this sample then. it uses Task.WhenAll to wait for more than one task.

https://msdn.microsoft.com/en-us/library/hh556530.aspx

Sergey Alexandrovich Kryukov 25-Feb-15 6:36am    
Do you mean you want to block the main thread for waiting? No kidding?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900