Return multiple asynch calls synchronously?
-
Hi! I want to to fire a number of asynch method calls from a main thread and have the main thread return true synchronously if the method calls all return true, otherwise false. The asynch method calls should have a timeout which makes them return false. How to best implement in .NET 2.0? Performance is an issue! Pseudo code:
public void main() { SynchObj sObj = new SynchObj(); bool allTrue = sObj.SynchCall(); } public class SynchObj { public bool SynchCall() { bool allTrue = false; // Create X objects with 3sek timeout // Fire Asynch calls // Suspend main thread until all X objects // ...have returned or timed out // Resume thread and set allTrue = true if all return allTrue; } } public class AsynchObj { public bool AsynchCall(int timeout) { // Make calculation // Return true or false (if timeout, return false) } }
-
Hi! I want to to fire a number of asynch method calls from a main thread and have the main thread return true synchronously if the method calls all return true, otherwise false. The asynch method calls should have a timeout which makes them return false. How to best implement in .NET 2.0? Performance is an issue! Pseudo code:
public void main() { SynchObj sObj = new SynchObj(); bool allTrue = sObj.SynchCall(); } public class SynchObj { public bool SynchCall() { bool allTrue = false; // Create X objects with 3sek timeout // Fire Asynch calls // Suspend main thread until all X objects // ...have returned or timed out // Resume thread and set allTrue = true if all return allTrue; } } public class AsynchObj { public bool AsynchCall(int timeout) { // Make calculation // Return true or false (if timeout, return false) } }
Have you looked at WaitHandle.WaitAll ?
only two letters away from being an asset