if a wav file is locked then keep checking if its locked and if it unlocks then continue the process, do this for all wavs that are still locked

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NAudio.Wave;

namespace ByteBreath
{
    public class WavCombiner
    {
        // PCM 16-bit 44.1kHz stereo
        private readonly WaveFormat targetFormat = new WaveFormat(44100, 16, 2);

        public void ConcatenateWavFiles(string inputFolder, string outputFilePath)
        {
            if (string.IsNullOrWhiteSpace(inputFolder))
                throw new ArgumentException("Input folder path must be specified.", nameof(inputFolder));

            if (string.IsNullOrWhiteSpace(outputFilePath))
                throw new ArgumentException("Output file path must be specified.", nameof(outputFilePath));

            if (!Directory.Exists(inputFolder))
                throw new DirectoryNotFoundException($"Input folder does not exist: {inputFolder}");

            var wavFiles = Directory.GetFiles(inputFolder, "*.wav")
                                    .OrderBy(f => f)
                                    .ToList();

            if (wavFiles.Count == 0)
                throw new FileNotFoundException("No WAV files found in the specified folder.");

            foreach (var wavFile in wavFiles)
            {
                ConvertToTargetFormat(wavFile);
            }

            byte[] buffer = new byte[1024 * 4];
            WaveFileWriter waveFileWriter = null;

            try
            {
                foreach (string wavFile in wavFiles)
                {
                    using (var reader = new WaveFileReader(wavFile))
                    {
                        if (waveFileWriter == null)
                        {
                            waveFileWriter = new WaveFileWriter(outputFilePath, reader.WaveFormat);
                        }
                        else
                        {
                            if (!reader.WaveFormat.Equals(waveFileWriter.WaveFormat))
                            {
                                throw new InvalidOperationException($"Unexpected different wave format in file {wavFile} after conversion.");
                            }
                        }

                        int bytesRead;
                        while ((bytesRead = reader.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            waveFileWriter.Write(buffer, 0, bytesRead);
                        }
                    }
                }
            }
            finally
            {
                waveFileWriter?.Dispose();
            }
        }

        private void ConvertToTargetFormat(string wavFilePath)
        {
            using (var reader = new AudioFileReader(wavFilePath))
            {
                if (reader.WaveFormat.SampleRate == targetFormat.SampleRate &&
                    reader.WaveFormat.BitsPerSample == targetFormat.BitsPerSample &&
                    reader.WaveFormat.Channels == targetFormat.Channels)
                {
                    return;
                }

                string tempFile = Path.Combine(Path.GetDirectoryName(wavFilePath),
                                               Path.GetFileNameWithoutExtension(wavFilePath) + "_temp.wav");

                using (var resampler = new MediaFoundationResampler(reader, targetFormat))
                {
                    resampler.ResamplerQuality = 60;
                    WaveFileWriter.CreateWaveFile(tempFile, resampler);
                }

                File.Delete(wavFilePath);
                File.Move(tempFile, wavFilePath);
            }
        }
    }
}