public void SubscribeToEventsFile(string filePath = "/var/log/apcupsd.events", int fileOpenTimeoutMs = 500)
        {
            if (this.subscribed)
            {
                throw new Exception("Already subscribed to a file.  You must first unsubscribe before subscribing again.");
            }

            this.shouldStop             = false;
            this.fileSubscriptionThread = new Thread(eventFileThread);
            var manualResetEvent  = new ManualResetEvent(false);
            var threadStartObject = new ThreadStartObject()
            {
                FilePath         = filePath,
                ManualResetEvent = manualResetEvent
            };

            this.fileSubscriptionThread.Start(threadStartObject);

            if (!manualResetEvent.WaitOne(fileOpenTimeoutMs))
            {
                this.shouldStop = true;
                this.fileSubscriptionThread.Abort();
                throw new TimeoutException($"Thread did not start reading within specified timeout {fileOpenTimeoutMs}ms");
            }
            this.subscribed = true;
        }
Example #2
0
    public static int Main(string[] args)
    {
        // check args
        if(args.Length != 1)
        {
            Console.WriteLine("USAGE: ThreadStartObject <object>|min|max\n");
            return -1;
        }

        ThreadStartObject tso = new ThreadStartObject();
        return tso.Run(args[0]);
    }
Example #3
0
    public static int Main(string[] args)
    {
        // check args
        if (args.Length != 1)
        {
            Console.WriteLine("USAGE: ThreadStartObject <object>|min|max\n");
            return(-1);
        }

        ThreadStartObject tso = new ThreadStartObject();

        return(tso.Run(args[0]));
    }