# Multiple-File Processing Methods - CaptureVisionRouter Class

| Method                                                              | Description                                                                  |
| ------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| [`SetInput`](#setinput)                                             | Sets an image source to provide images for consecutive processing.         |
| [`GetInput`](#getinput)                                             | Gets the attached image source adapter object of the capture vision router.         |
| [`AddCaptureStateListener`](#addcapturestatelistener)               | Adds an object that listens to the state changes of the capture process.     |
| [`RemoveCaptureStateListener`](#removecapturestatelistener)         | Removes an object which listens to the state changes of the capture process. |
| [`AddImageSourceStateListener`](#addimagesourcestatelistener)       | Adds an object that listens to state changes of the image source.            |
| [`RemoveImageSourceStateListener`](#removeimagesourcestatelistener) | Removes an object which listens to state changes of the image source.        |
| [`AddResultReceiver`](#addresultreceiver)                           | Adds an object as the receiver of captured results.                          |
| [`RemoveResultReceiver`](#removeresultreceiver)                     | Removes an object which was added as a receiver of captured results.         |
| [`AddResultFilter`](#addresultfilter)                               | Adds an object as the filter of captured results.                          |
| [`RemoveResultFilter`](#removeresultfilter)                         | Removes an object which was added as a filter of captured results.         |
| [`StartCapturing`](#startcapturing)                                 | Starts to process images consecutively.                                      |
| [`StopCapturing`](#stopcapturing)                                   | Stops the consecutive processing.                                          |
| [`PauseCapturing`](#pausecapturing)                                 | Pauses the capture process. The current thread will be blocked until the capture process is resumed. |
| [`ResumeCapturing`](#resumecapturing)                               | Resumes the capture process. The current thread will be unblocked after the capture process is resumed. |
| [`SwitchCapturingTemplate`](#switchcapturingtemplate)      | Switches the capturing template during the image processing workflow.                            |

## SetInput

Sets an image source to provide images for consecutive processing.

```csharp
int SetInput(ImageSourceAdapter pAdaptor)
```

**Parameters**

`[in] pAdaptor` Specifies an object which has implemented the [Image Source Adapter Interface](https://www.dynamsoft.com/capture-vision/docs/core/architecture/input.md#image-source-adapter).

**Return Value**

Returns an error code. Zero indicates success.

| Error Code | Value | Description |
| :--------- | :---- | :---------- |
| EC_CALL_REJECTED_WHEN_CAPTURING  | -10062 | Function call is rejected when capturing in progress. |

**See Also**

[ImageSourceAdapter](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/core/basic-classes/image-source-adapter.md)

[DirectoryFetcher](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/utility/directory-fetcher.md)

[FileFetcher](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/utility/file-fetcher.md)

## GetInput

Gets the attached image source adapter object of the capture vision router. 

```csharp
ImageSourceAdapter GetInput()
```

**Return Value**

Returns the attached image source adapter object of the capture vision router.

**See Also**

[ImageSourceAdapter](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/core/basic-classes/image-source-adapter.md)

[DirectoryFetcher](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/utility/directory-fetcher.md)

[FileFetcher](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/utility/file-fetcher.md)

## AddCaptureStateListener

Adds an object that listens to the state changes of the capture process.

```csharp
int AddCaptureStateListener(ICaptureStateListener listener)
```

**Parameters**

`[in] listener` Specifies a listening object of the type [`ICaptureStateListener`](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/capture-state-listener.md) to be added.

**Return Value**

Returns an error code. Zero indicates success.

**See Also**

[ICaptureStateListener](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/capture-state-listener.md)

## RemoveCaptureStateListener

Removes an object which listens to the state changes of the capture process.

```csharp
int RemoveCaptureStateListener(ICaptureStateListener listener)
```

**Parameters**

`[in] listener` Specifies a listening object of the type [`ICaptureStateListener`](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/capture-state-listener.md) to be removed.

**Return Value**

Returns an error code. Zero indicates success.

**See Also**

[ICaptureStateListener](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/capture-state-listener.md)

## AddImageSourceStateListener

Adds an object that listens to state changes of the image source.

```csharp
int AddImageSourceStateListener(IImageSourceStateListener listener)
```

**Parameters**

`[in] listener` Specifies a listening object of the type [`IImageSourceStateListener`](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/image-source-state-listener.md) to be added.

**Return Value**

Returns an error code. Zero indicates success.

**See Also**

[IImageSourceStateListener](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/image-source-state-listener.md)

## RemoveImageSourceStateListener

Removes an object which listens to state changes of the image source.

```csharp
int RemoveImageSourceStateListener(IImageSourceStateListener listener)
```

**Parameters**

`[in] listener` Specifies a listening object of the type [`IImageSourceStateListener`](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/image-source-state-listener.md) to be removed.

**Return Value**

Returns an error code. Zero indicates success.

**See Also**

[IImageSourceStateListener](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/image-source-state-listener.md)

## AddResultReceiver

Adds an object as the receiver of captured results.

```csharp
int AddResultReceiver(CapturedResultReceiver receiver)
```

**Parameters**

`[in] receiver` Specifies a receiver object of the type [`CapturedResultReceiver`](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/captured-result-receiver.md) to be added.

**Return Value**

Returns an error code. Zero indicates success.

**See Also**

[CapturedResultReceiver](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/captured-result-receiver.md)

## RemoveResultReceiver

Removes an object which was added as a receiver of captured results.

```csharp
int RemoveResultReceiver(CapturedResultReceiver receiver)
```

**Parameters**

`[in] receiver` Specifies a receiver object of the type [`CapturedResultReceiver`](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/captured-result-receiver.md) to be removed.

**Return Value**

Returns an error code. Zero indicates success.

**See Also**

[CapturedResultReceiver](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/captured-result-receiver.md)

## AddResultFilter

Adds an object as the filter of captured results.

```csharp
int AddResultFilter(CapturedResultFilter filter)
```

**Parameters**

`[in] filter` Specifies a filter object of the type [`CapturedResultFilter`](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/captured-result-filter.md) to be added.

**Return Value**

Returns an error code. Zero indicates success.

**See Also**

[CapturedResultFilter](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/captured-result-filter.md)

## RemoveResultFilter

Removes an object which was added as a filter of captured results.

```csharp
int RemoveResultFilter(CapturedResultFilter filter)
```

**Parameters**

`[in] filter` Specifies a filter object of the type [`CapturedResultFilter`](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/captured-result-filter.md) to be removed.

**Return Value**

Returns an error code. Zero indicates success.

**See Also**

[CapturedResultFilter](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/captured-result-filter.md)

## StartCapturing

Starts to process images consecutively.

```csharp
int StartCapturing(string templateName, bool waitForThreadExit, out string errorMsgBuffer)
```

**Parameters**

`[in] templateName` Specifies a `CaptureVisionTemplate` to use for capturing.

`[in] waitForThreadExit` Indicates whether to wait for the capture process to complete before returning.

`[out] errorMsgBuffer` Stores any error messages generated during the capturing process.

**Remarks**

- There are two types of `CaptureVisionTemplate`: the [preset ones](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/auxiliary-classes/preset-template.md) which come with the SDK and the custom ones that get initialized when the user calls [InitSettings](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/settings.md#initsettings) / [InitSettingsFromFile](https://www.dynamsoft.com/capture-vision/docs/server/programming/dotnet/api-reference/capture-vision-router/settings.md#initsettingsfromfile).
- When using a custom template, the parameter `templateName` should be the name of the [`CaptureVisionTemplate` object](https://www.dynamsoft.com/capture-vision/docs/core/parameters/reference/capture-vision-template/index.md) in the JSON template file.
- Please be aware that the preset `CaptureVisionTemplates` will be overwritten should the user call `InitSettings` / `InitSettingsFromFile` and pass his own settings.
- If parameter `templateName` is not specified, the preset one named 'Default' will be used. However, if the preset ones have been overwritten as described above, the first `CaptureVisionTemplate` from the user's own settings will be used instead.

**Return Value**

The function returns an integer value representing the success or failure of the capturing process. A value of 0 indicates success, while a non-zero value indicates failure. Any error messages generated during the capturing process will be returned in `errorMsgBuffer`.

| Error Code | Value | Description |
| :--------- | :---- | :---------- |
| EC_TEMPLATE_NAME_INVALID | -10036 | The target template name is invalid. |
| EC_CALL_REJECTED_WHEN_CAPTURING  | -10062 | Function call is rejected when capturing in progress. |
| EC_NO_IMAGE_SOURCE | -10063 | Can not start capturing before you set the input. |

## StopCapturing

Stops the multiple-file processing.

```csharp
void StopCapturing(bool waitForRemainingTasks = true, bool waitForThreadExit = false)
```

**Parameters**

`[in] waitForRemainingTasks` Indicates whether to wait for the remaining tasks to complete before returning. The default value is true.  
`[in] waitForThreadExit` Indicates whether to wait for the capture process to complete before returning. The default value is false.


## PauseCapturing

Pauses the capture process. The current thread will be blocked until the capture process is resumed.

```csharp
void PauseCapturing()
```

## ResumeCapturing

Resumes the capture process. The current thread will be unblocked after the capture process is resumed.

```csharp
void ResumeCapturing()
```

## SwitchCapturingTemplate

Switches the capturing template during the image processing workflow.

```csharp
public int SwitchCapturingTemplate(string templateName)
```

**Parameters**

`[in] templateName` The name of the new capturing template to apply.

**Return value**

Returns an error code. Zero indicates success.

**Remarks**

- Introduced in Dynamsoft Barcode Reader SDK version 11.2.1000 and Dynamsoft Capture Vision version 3.2.1000.
