using System;
using System.IO.MemoryMappedFiles;
using System.Threading;

namespace AR.MemoryMap
{
    public class Client : Core
    {
        public Client(string MapFileName, int MapFileSize, int loopDelay = 50) : base(MapFileName, MapFileSize, loopDelay)
        {
            StartAction = () =>
            {
                try
                {
                    var MapFileSync = $"{MapFileName}{MapFileSize}";
                    mmf = MemoryMappedFile.CreateOrOpen(MapFileName, MapFileSize);
                    mutex = new Mutex(false, MapFileSync, out mutexCreated);
                    ErrorMessage = string.Empty;
                    return true;
                }
                catch (Exception ex)
                {
                    ErrorMessage = ex.Message;
                    return false;
                }

            };
            StopAction = () =>
            {
                ErrorMessage = string.Empty;
                brun = false;
                return true;
            };
        }
    }
}
