示例#1
0
/// <summary>
/// Add a new connection
/// </summary>
/// <param name="connectionString"></param>
/// <param name="accountName"></param>
/// <param name="accountPw"></param>
/// <param name="interactive"></param>

        public static void AddConnection(
            string connectionString,
            string accountName,
            string accountPw,
            bool interactive)
        {
            try
            {
                int t0 = TimeOfDay.Milliseconds();
                connectionString = NormalizeConnectionStringToUncShareName(connectionString);

                CancelConnection(connectionString);                 // try to cancel first (seems to make reconnect faster)

                NetworkConnectionWorker worker = new NetworkConnectionWorker();
                worker.connectionString = connectionString;
                worker.directoryExists  = false;

                worker.accountName = accountName;
                worker.accountPw   = accountPw;
                worker.interactive = interactive;

                Thread workerThread = new Thread(new ThreadStart(worker.AddConnection));
                workerThread.Name = "AddConnection";
                workerThread.Start();
                while (!workerThread.IsAlive)
                {
                    ;                                           // loop until worker thread activates.
                }
                while (workerThread.IsAlive)
                {
                    Thread.Sleep(10);
                    Application.DoEvents();
                }

                //workerThread.Join();
                if (worker.ex != null)
                {
                    throw worker.ex;
                }
            }
            catch (Exception ex)
            {
                DebugLog.Message("AddConnection exception: " + DebugLog.FormatExceptionMessage(ex));
            }
            return;
        }
示例#2
0
/// <summary>
/// Check if directory exists
/// </summary>
/// <param name="connectionString"></param>
/// <returns></returns>

        public static bool DirectoryExists(string path)
        {
            NetworkConnectionWorker worker = new NetworkConnectionWorker();

            worker.path            = path;
            worker.directoryExists = false;

            int t0 = TimeOfDay.Milliseconds();

            if (DebugAddConnection)
            {
                DebugLog.Message(
                    "Calling Directory.Exists for: " + path);
            }

            Thread workerThread = new Thread(new ThreadStart(worker.DirectoryExists));

            workerThread.Name = "DirectoryExists";
            workerThread.Start();
            while (!workerThread.IsAlive)
            {
                ;                                    // loop until worker thread activates.
            }
            while (workerThread.IsAlive)             // allow limited time to check since may be slow if doesn't exist (~25 secs)
            {
                Thread.Sleep(10);
                Application.DoEvents();
            }

            //workerThread.Join(); // (don't join because causes delay)

            if (DebugAddConnection)
            {
                DebugLog.Message(
                    "Exists = " + worker.directoryExists + " time (ms): " + (TimeOfDay.Milliseconds() - t0).ToString());
            }

            return(worker.directoryExists);
        }