Table of Contents

Class CommandListener

Namespace
VpnHood.Core.Common
Assembly
VpnHood.Core.Common.dll

Passes commands between runs of an app through a file: one run writes a command line to it, and another, watching it, gets the command's arguments.

public class CommandListener : IDisposable
Inheritance
CommandListener
Implements
Inherited Members
Extension Methods

Constructors

CommandListener(string)

Passes commands between runs of an app through a file: one run writes a command line to it, and another, watching it, gets the command's arguments.

public CommandListener(string commandFilePath)

Parameters

commandFilePath string

The command file's path.

Properties

CommandFilePath

Gets the command file's path.

public string CommandFilePath { get; }

Property Value

string

IsStarted

Gets a value indicating whether the listener is watching the file.

public bool IsStarted { get; }

Property Value

bool

Methods

Dispose()

Stops watching the command file.

public void Dispose()

OnCommand(string[])

protected void OnCommand(string[] args)

Parameters

args string[]

The command's arguments.

SendCommand(string)

Writes a command line to the command file, for the run that watches it.

public void SendCommand(string command)

Parameters

command string

The command line.

Start()

Starts watching the command file, making its folder if missing, then deletes a command an earlier run left.

public void Start()

Remarks

A failure to start is logged, and leaves the listener stopped or watching, as far as it got.

Exceptions

Exception

The listener is started already.

Stop()

Stops watching the command file.

public void Stop()

TrySendCommand(string)

Writes a command line to the command file, as SendCommand(string) does, logging a failure.

public void TrySendCommand(string command)

Parameters

command string

The command line.

Events

CommandReceived

Occurs when the command file is written, with its command line split into arguments, on the file watcher's thread. A failure to read the file or of a handler is logged.

public event EventHandler<CommandReceivedEventArgs>? CommandReceived

Event Type

EventHandler<CommandReceivedEventArgs>