Пример #1
0
        public virtual void Run()
        {
            //winrt
            //Thread runThread = Thread.CurrentThread();
            Exception ex0 = null;

            try
            {
                DoConnect();
            }
            catch (Exception ex)
            {
                ex0 = ex;
                // Defer to below where we're locked
                return;
            }
            finally
            {
                //winrt
                if (null != Thread)
                {
                    lock (Thread)
                    {
                        //if (runThread != Thread)
                        //{
                        if (ex0 != null)
                        {
                            if (Log.Level >= 2)
                            {
                                Runtime.PrintStackTrace(ex0, Log);
                            }
                        }
                        //}
                        if (ex0 != null)
                        {
                            Te = new TransportException(ex0);
                        }
                        State = 2;
                        // run connected
                        Runtime.Notify(Thread);
                    }
                }
            }
            Loop();
        }
Пример #2
0
        /// <exception cref="WinrtCifs.Util.Transport.TransportException"></exception>
        public virtual void Connect(long timeout)
        {
            lock (this)
            {
                try
                {
                    switch (State)
                    {
                    case 0:
                    {
                        break;
                    }

                    case 3:
                    {
                        return;
                    }

                    case 4:
                    {
                        // already connected
                        State = 0;
                        throw new TransportException("Connection in error", Te);
                    }

                    default:
                    {
                        //TransportException te = new TransportException("Invalid state: " + state);
                        State = 0;
                        throw new TransportException("Invalid state: " + State);
                    }
                    }
                    State  = 1;
                    Te     = null;
                    Thread = new Thread(this);
                    Thread.SetDaemon(true);
                    lock (Thread)
                    {
                        Thread.Start();
                        Runtime.Wait(Thread, timeout);
                        switch (State)
                        {
                        case 1:
                        {
                            State  = 0;
                            Thread = null;
                            throw new TransportException("Connection timeout");
                        }

                        case 2:
                        {
                            if (Te != null)
                            {
                                State  = 4;
                                Thread = null;
                                throw Te;
                            }
                            State = 3;
                            return;
                        }
                        }
                    }
                }
                catch (Exception ie)
                {
                    State  = 0;
                    Thread = null;
                    throw new TransportException(ie);
                }
                finally
                {
                    if (State != 0 && State != 3 && State != 4)
                    {
                        if (Log.Level >= 1)
                        {
                            Log.WriteLine("Invalid state: " + State);
                        }
                        State  = 0;
                        Thread = null;
                    }
                }
            }
        }