public bool AddReadTask( NamedPipeClientStream pipeStream, LazysplitsComponent lzsComponent ) { if( !IsTaskInList( PipeTaskType.Read ) ) { PipeTaskRead ReadTask = new PipeTaskRead( pipeStream, lzsComponent ); if( ReadTask.StartTask() ) { PipeTaskList.Add(ReadTask); Log.Trace("Pipe read task added"); return true; } } return false; }
public void WaitOnTasks( LazysplitsComponent lzsComponent ) { if( PipeTaskList.Count > 0 ) { try { //populate array of tasks to wait on Task[] TaskArray = new Task[PipeTaskList.Count]; for( int i = 0; i < PipeTaskList.Count; i++ ){ TaskArray[i] = PipeTaskList[i].GetTask(); } //refresh our cancellation token if needed if(WaitTokenSource.Token.IsCancellationRequested) { WaitTokenSource.Dispose(); WaitTokenSource = new CancellationTokenSource(); } //wait on any Log.Trace( "waiting on {0} tasks", TaskArray.Length ); bIsWaiting = true; int SignalledTaskIndex = Task.WaitAny( TaskArray.ToArray(), WaitTokenSource.Token ); bIsWaiting = false; //wait finished, handle result IPipeTask CurrentTask = PipeTaskList[SignalledTaskIndex]; CurrentTask.HandleTaskResult(); //handle status icons if enabled from our LiveSplit component...really ugly if( lzsComponent.Settings.bStatusIconsEnabled ) { if( CurrentTask.GetTask().Status == TaskStatus.RanToCompletion ) { if( CurrentTask.GetTaskType() == PipeTaskType.Read ){ lzsComponent.MsgPipeData(LsPipeDataType.Received); } else if( CurrentTask.GetTaskType() == PipeTaskType.Write ){ lzsComponent.MsgPipeData(LsPipeDataType.Sent); } } } //dispose of task and remove from list Log.Trace( "Removing {0} from list", Enum.GetName( typeof(PipeTaskType), CurrentTask.GetTaskType() ) ); PipeTaskList.RemoveAt(SignalledTaskIndex); } catch(OperationCanceledException){ Log.Trace("Task wait cancelled"); } } }
public PipeTaskRead(NamedPipeClientStream pipeStreamInstance, LazysplitsComponent lzsComponent) : base(PipeTaskType.Read, pipeStreamInstance) { LzsComponent = lzsComponent; }
public LzsPipeClient(string threadName, string pipeName, LazysplitsComponent lzsComponent) : base(threadName) { PipeName = pipeName; LzsComponent = lzsComponent; MsgQueue = new LzsMessageQueue <byte[]>("PipeClient message queue"); }