79409217

Date: 2025-02-03 15:17:31
Score: 0.5
Natty:
Report link

This is work (_stream and _listener are private fields, initialising into task):

    public void Stop()
    {
        if (_listenTask != null)
        {
            _source.Cancel();

            try
            {
                _stream?.Close();
            }
            catch (Exception)
            { }

            try
            {
                _listener?.Stop();
            }
            catch (Exception)
            { }

            while (!(_listenTask.IsCanceled || _listenTask.IsCompleted || _listenTask.IsFaulted))
            {
                Thread.Sleep(1);
            }

            _listenTask = null;
            _source = null;
        }
    }
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: user29484439