Esempio n. 1
0
        private IntPtr AcquireHandle()
        {
            IntPtr Handle;

            Monitor.Enter(this);
            try
            {
                if (this.handleCount == 0)
                {
                    int RetryConnectCount = 100;
                    while (this.handle == IntPtr.Zero)
                    {
                        try
                        {
                            this.handle = ScpCommands.Open(this.port);
                        }
                        catch
                        {
                            if (RetryConnectCount > 0)
                            {
                                Thread.Sleep(new Random().Next(1, 50));
                                RetryConnectCount--;
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }

                this.handleCount++;
                Handle = this.handle;
            }
            finally
            {
                Monitor.Exit(this);
            }
            return(Handle);
        }