/// <summary>
        /// Initializes the reader asynchronous.
        /// </summary>
        /// <param name="path">The location of the image.</param>
        /// <param name="ct">The cancellation token.</param>
        /// <returns>
        /// A <see cref="Task" /> representing the asynchronous operation.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// path
        /// or
        /// ct
        /// </exception>
        /// <exception cref="AmiException">The ITK image could not be read.</exception>
        public async Task InitAsync(string path, CancellationToken ct)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (ct == null)
            {
                throw new ArgumentNullException(nameof(ct));
            }

            await SemaphoreSlim.WaitAsync();

            try
            {
                Image = await itkUtil.ReadImageAsync(path, ct);

                if (Image == null)
                {
                    throw new AmiException("The ITK image could not be read.");
                }

                size       = Image.GetSize();
                axisImages = new Dictionary <AxisType, Image>();
            }
            finally
            {
                SemaphoreSlim.Release();
            }
        }
Пример #2
0
        /// <inheritdoc/>
        public async Task InitAsync(string path, CancellationToken ct)
        {
            Ensure.ArgumentNotNull(path, nameof(path));
            Ensure.ArgumentNotNull(ct, nameof(ct));

            await SemaphoreSlim.WaitAsync();

            try
            {
                Image = await itkUtil.ReadImageAsync(path, ct);

                if (Image == null)
                {
                    throw new AmiException("The ITK image could not be read.");
                }

                size = Image.GetSize();
            }
            finally
            {
                SemaphoreSlim.Release();
            }
        }