WaitSet waitset = new WaitSet();
Condition cond1 = entity.get_statuscondition(); Condition cond2 = reader.create_readcondition( SampleStateKind.NOT_READ_SAMPLE_STATE, ViewStateKind.ANY_VIEW_STATE, InstanceStateKind.ANY_INSTANCE_STATE); Condition cond3 = new GuardCondition(); try { waitset.attach_condition(cond1); waitset.attach_condition(cond2); waitset.attach_condition(cond3); } catch (DDS.Exception) { // ... error }
timeout
, whichever occurs first Duration_t timeout; timeout.sec = 0; timeout.nanosec = 1000000; // 1ms // holder for active conditions ConditionSeq active_conditions = new ConditionSeq(); bool is_cond1_triggered = false; bool is_cond2_triggered = false; try { waitset.wait(active_conditions, timeout); // check if "cond1" or "cond2" are triggered: for (int i = 0; i < active_conditions.length; ++i) { if (active_conditions.get_at(i) == cond1) { Console.WriteLine("Cond1 was triggered!"); is_cond1_triggered = true; } if (active_conditions.get_at(i) == cond2) { Console.WriteLine("Cond2 was triggered!"); is_cond2_triggered = true; } } if (is_cond1_triggered) { // ... do something because "cond1" was triggered ... } if (is_cond2_triggered) { // ... do something because "cond2" was triggered ... } } catch (DDS.Retcode_Timeout) { // timeout! Console.WriteLine( "Wait timed out!! None of the conditions was triggered."); } catch (DDS.Exception) { // ... check for cause of failure throw; }
waitset.Dispose(); waitset = null;