Example #1
0
        /// <summary>
        /// Starts the client.
        /// </summary>
        public async Task Start(CancellationToken cancellationToken)
        {
            using (await lck.LockAsync())
            {
                if (State != RnetClientState.Stopped)
                    throw new RnetException("Client is already started.");

                // start up receiver using a background task
                cts = new CancellationTokenSource();
                receiveTask = Task.Run(async () => await ReceiveLoop(cts.Token));

                // currenty started
                State = RnetClientState.Started;
            }

            OnStateChanged(new RnetClientStateEventArgs(State));
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="state"></param>
 internal RnetClientStateEventArgs(RnetClientState state)
 {
     State = state;
 }
Example #3
0
        /// <summary>
        /// Stops the client.
        /// </summary>
        public async Task Stop(CancellationToken cancellationToken)
        {
            using (await lck.LockAsync())
            {
                if (State != RnetClientState.Started)
                    return;

                // signal shutdown
                cts.Cancel();
                State = RnetClientState.Stopped;

                // wait for receiving task to terminate
                await receiveTask;
                receiveTask = null;
            }

            OnStateChanged(new RnetClientStateEventArgs(State));
        }