FileLockerLib 0.0.24

synchronise processes using shared file, every process try to lock a file

Install-Package FileLockerLib -Version 0.0.24
dotnet add package FileLockerLib --version 0.0.24
<PackageReference Include="FileLockerLib" Version="0.0.24" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FileLockerLib --version 0.0.24
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

FlieLockLib

Simple library for synchronize processes using file as lock.

alt text

Usage:

 static FileLocker locker;
        static int releaseCounter = 0;
        static int releaseAfter = 10;

        static void Main(string[] args)
        {
            //the name of the lock need to be accepted by all processes
            string fileLockPath = @"C:\Users\proxytype\Desktop\filelocker.lck";
            //create new file locker
            locker = new FileLocker(true);
            //signin the filelocker events
            locker.FileLockerHandler += Locker_FileLockerHandler;

            //for the example the file going to be lock and release
            while (true) {

                locker.lockFile(fileLockPath);
                Random random = new Random();
                int value =  random.Next(100, 1000);
                Thread.Sleep(value);

                if (locker.isLock)
                {
                    releaseCounter = releaseCounter + 1;
                    if (releaseCounter > releaseAfter)
                    {
                        releaseCounter = 0;
                        locker.unlockFile();

                        Thread.Sleep(2000);
                    }

                }
                else {
                    Thread.Sleep(value);
                }
            }
        }

        //getting feedback from the locker
        private static void Locker_FileLockerHandler(FileLockerPayload payload)
        {
            Console.WriteLine(Process.GetCurrentProcess().ProcessName 
            + " - Locker Response:" + payload.code.ToString() 
            + " Message:" + payload.message);
        }

FlieLockLib

Simple library for synchronize processes using file as lock.

alt text

Usage:

 static FileLocker locker;
        static int releaseCounter = 0;
        static int releaseAfter = 10;

        static void Main(string[] args)
        {
            //the name of the lock need to be accepted by all processes
            string fileLockPath = @"C:\Users\proxytype\Desktop\filelocker.lck";
            //create new file locker
            locker = new FileLocker(true);
            //signin the filelocker events
            locker.FileLockerHandler += Locker_FileLockerHandler;

            //for the example the file going to be lock and release
            while (true) {

                locker.lockFile(fileLockPath);
                Random random = new Random();
                int value =  random.Next(100, 1000);
                Thread.Sleep(value);

                if (locker.isLock)
                {
                    releaseCounter = releaseCounter + 1;
                    if (releaseCounter > releaseAfter)
                    {
                        releaseCounter = 0;
                        locker.unlockFile();

                        Thread.Sleep(2000);
                    }

                }
                else {
                    Thread.Sleep(value);
                }
            }
        }

        //getting feedback from the locker
        private static void Locker_FileLockerHandler(FileLockerPayload payload)
        {
            Console.WriteLine(Process.GetCurrentProcess().ProcessName 
            + " - Locker Response:" + payload.code.ToString() 
            + " Message:" + payload.message);
        }

  • .NETStandard 2.0

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
0.0.24 72 6/29/2019