NavigationCmdletProvider để xác định xem nhà cung cấp dịch vụ của bạn cần hỗ trợ chuyển hướng. Cũng như trước đây, một số phương pháp gọi lại được thừa kế, mỗi tương ứng với một lệnh cụ thể. Ngoài ra, mỗi của những người có một phương pháp gọi lại cho các thông số năng động, | Chapter 6 Hosting the PowerShell Engine in Applications The script block in this example runs the get-process cmdlet and pauses for one second after each object it produces. Closing the Input Pipe If you compile and execute the preceding example you ll find a counterintuitive quirk of the API No matter how long you leave the pipeline running no objects will appear in the output pipe. That s because after you call InvokeAsync execution of the pipeline is actually suspended until you close the input pipe. If you modify the code as follows the pipeline will execute Runspace runspace Pipeline pipeline gps foreach sleep 1 _ Calling Close on the input pipe while it s already closed won t throw an exception but you can check the state of the pipe using the PipelineWriter class s IsOpen property. Reading Output and Error from an Asynchronous Pipeline At this point if the script block you re running in the pipeline has some effect other than writing objects then you ll be able to see it but you still haven t received the output of the pipeline. The next step is to read objects from the running pipeline s output and error pipes. The Output and Error properties of the pipeline are instances of the generic PipelineReader T class which contains methods for detecting when objects are available and for reading the available objects in several different ways. The following table lists the methods you can use to read objects from PipelineReader. Method Description Read Reads one object and blocks if it isn t available Read count Reads count objects and blocks until all are read ReadToEnd Reads until the pipe is closed Peek Checks whether any objects are available to read NonBlockingRead NonBlockingRead count Reads one object and returns immediately if there isn t one Reads count objects and returns immediately if there aren t enough PipelineReader also provides a .