本文整理汇总了C#中WorkflowExecutionContext.WaitAny方法的典型用法代码示例。如果您正苦于以下问题:C# WorkflowExecutionContext.WaitAny方法的具体用法?C# WorkflowExecutionContext.WaitAny怎么用?C# WorkflowExecutionContext.WaitAny使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorkflowExecutionContext
的用法示例。
在下文中一共展示了WorkflowExecutionContext.WaitAny方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SayAndWaitEvents
private NextActivityKey SayAndWaitEvents(
WorkflowExecutionContext context,
string text, string[] sounds, string helpText, string[] helpSounds,
bool silent, bool ignoreButtons,
ICollection<WaitHandle> waitedEvents, int startTimeout, int repeatTimeout,
NextActivityKeyResolver nextActivityKeyResolver, out int occurredEventIndex)
{
var filteredWaitedEvents = new List<WaitHandle>(waitedEvents.Count + 1);
var needWaitKeyPressed = false;
var needWaitHelpPressed = false;
foreach (var currentEvent in waitedEvents)
{
var keyWh = currentEvent as KeyPressedWaitHandle;
if (keyWh != null)
{
needWaitKeyPressed = true;
if (keyWh.Equals(KeyPressedWaitHandle.HelpPressed))
{
needWaitHelpPressed = true;
}
else if (ignoreButtons)
{
continue;
}
}
filteredWaitedEvents.Add(currentEvent);
}
RaiseOutputStarting(needWaitKeyPressed ? InfoType.Question : InfoType.Information);
var lastWaitedEventsIndex = filteredWaitedEvents.Count - 1;
var playSoundFinishedEvent = new ManualResetEvent(false);
filteredWaitedEvents.Add(playSoundFinishedEvent);
var waitedEventsDuringPlaying = filteredWaitedEvents.ToArray();
if (!needWaitHelpPressed)
{
filteredWaitedEvents[filteredWaitedEvents.Count - 1] = KeyPressedWaitHandle.HelpPressed;
}
else
{
filteredWaitedEvents.RemoveAt(filteredWaitedEvents.Count - 1);
}
var waitedEventsAfterPlaying = filteredWaitedEvents.ToArray();
var helpButtonPressed = false;
if (startTimeout > 0 || startTimeout == Timeout.Infinite)
{
ResetEvents(waitedEventsAfterPlaying);
occurredEventIndex = context.WaitAny(waitedEventsAfterPlaying, startTimeout);
if (0 <= occurredEventIndex && occurredEventIndex <= lastWaitedEventsIndex)
return nextActivityKeyResolver(waitedEventsAfterPlaying[occurredEventIndex], context);
helpButtonPressed = (occurredEventIndex == waitedEventsAfterPlaying.Length - 1);
}
while (true)
{
if (helpButtonPressed && helpSounds != null && helpSounds.Length > 0)
occurredEventIndex = SetIndicatorAndPlayPhrase(
context, waitedEventsDuringPlaying, playSoundFinishedEvent,
helpText ?? text, helpSounds, false);
else
occurredEventIndex = SetIndicatorAndPlayPhrase(
context, waitedEventsDuringPlaying, playSoundFinishedEvent,
text, sounds, silent);
if (occurredEventIndex >= 0)
return nextActivityKeyResolver(waitedEventsDuringPlaying[occurredEventIndex], context);
ResetEvents(waitedEventsAfterPlaying);
occurredEventIndex = context.WaitAny(waitedEventsAfterPlaying, repeatTimeout);
if (0 <= occurredEventIndex && occurredEventIndex <= lastWaitedEventsIndex)
return nextActivityKeyResolver(waitedEventsAfterPlaying[occurredEventIndex], context);
helpButtonPressed = (occurredEventIndex == waitedEventsAfterPlaying.Length - 1);
}
}
示例2: SayPhrase
public NextActivityKey SayPhrase(WorkflowExecutionContext context, ActivityParameterDictionary parameters)
{
RaiseOutputStarting(InfoType.Information);
var silent = NeedSilent(parameters);
var composer = CreatePhraseComposer(parameters, silent);
var text = composer.ComposeText();
if (text.Length > 0)
{
_logger.LogInfo(Message.WorkflowText, text);
_scannerManager.SetIndicator(text);
}
if (silent)
return context.DefaultNextActivityKey;
var playSoundFinishedEvent = new AutoResetEvent(false);
var sounds = composer.ComposePhrase();
_soundManager.PlaySounds(sounds, (sender, e) => playSoundFinishedEvent.Set());
try
{
KeyPressedWaitHandle.YesOrNoPressed.Reset();
var index = context.WaitAny(
new WaitHandle[] {KeyPressedWaitHandle.YesOrNoPressed, playSoundFinishedEvent});
if (index == 0)
{
_soundManager.StopPlaying();
_logger.LogVerbose(Message.WorkflowSoundPlayingStoppedByYesOrNoPressed);
}
}
catch (ActivityExecutionInterruptException)
{
_soundManager.StopPlaying();
_logger.LogVerbose(Message.WorkflowSoundPlayingStoppedByActivityExecutionInterrupt);
throw;
}
return context.DefaultNextActivityKey;
}