示例#1
0
        /// <summary>
        ///     Handles a cancel event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ManageCancel(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            if (worker != null)
            {
                Thread thread = ThreadUtil.CreateThread("Progress" + Text, Work.TreadStart);
                thread.Start(Work);

                int percent = 0;
                while (thread.ThreadState != ThreadState.Stopped)
                {
                    Thread.Sleep(100);

                    if (worker.CancellationPending)
                    {
                        thread.Abort();
                        break;
                    }

                    // Show something moving
                    percent += 1;
                    if (percent > 100)
                    {
                        percent = 0;
                    }

                    worker.ReportProgress(percent);
                }
            }
        }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="instance"></param>
 /// <param name="cycleTime"></param>
 protected GenericSynchronizationHandler(T instance, int cycleTime)
     : base(cycleTime)
 {
     Instance = instance;
     Thread   = ThreadUtil.CreateThread("UI Synchronization", DoSynchronize);
     Thread.Start(Instance);
 }
示例#3
0
        private static void Main(string[] args)
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                XmlConfigurator.Configure(new FileInfo("logconfig.xml"));

                Options.Options.SetSettings();
                EfsSystem.Instance.DictionaryChangesOnFileSystem += HandleInstanceDictionaryChangesOnFileSystem;

                MainWindow window = new MainWindow();
                Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

                {
                    // TRICKY SECTION
                    // This thread is mandatory otherwise WCF does not create a new thread to handle the service requests.
                    // Since the call to Cycle is blocking, creating such threads is mandatory
                    Thread thread = ThreadUtil.CreateThread("EFS Service", HostEfsService);
                    thread.Start();
                }

                // Opens the Dictionary files and check them
                bool shouldPlace = true;
                foreach (string fileName in args)
                {
                    const bool        allowErrors       = false;
                    OpenFileOperation openFileOperation = new OpenFileOperation(fileName, EfsSystem.Instance, allowErrors, true);
                    openFileOperation.ExecuteUsingProgressDialog(GuiUtils.MdiWindow, "Opening file " + fileName, false);
                    if (openFileOperation.Dictionary != null)
                    {
                        window.SetupWindows(openFileOperation.Dictionary, shouldPlace);
                        shouldPlace = false;
                    }
                    else
                    {
                        Console.Out.WriteLine("Cannot open dictionary file " + fileName);
                    }
                }

                CheckModelOperation checkModel = new CheckModelOperation();
                checkModel.ExecuteUsingProgressDialog(GuiUtils.MdiWindow, "Checking model");

                Application.Run(window);
                CloseEfsService();
            }
            finally
            {
                Util.UnlockAllFiles();
            }

            EfsSystem.Instance.Stop();
            SynchronizerList.Stop();
        }