예제 #1
0
        private void StartShellForm(ShellForm shellForm)
        {
            if (shellForm == null)
            {
                return;
            }

            shellForm.WindowState = WindowState;
            var t = new System.Threading.Thread(() =>
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(shellForm);
            });

            t.SetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
            Close();
        }
예제 #2
0
        private async void SplashForm_Load(object sender, EventArgs e)
        {
            a                = 0;
            frameNumber      = 0;
            speed            = MaxWaveSpeed;
            speedDelta       = -1;
            messageIndex     = 0;
            messageStep      = 0;
            requestNextFrame = true;

            animationTimer          = new Timer();
            animationTimer.Tick    += AnimationTimer_Tick;
            animationTimer.Interval = 100;
            animationTimer.Start();

            messageTimer = new System.Threading.Timer(_ =>
            {
                messageStep++;
                if (messageStep == MaxMessageStep + 1)
                {
                    messageStep = 0;
                    messageIndex++;
                    if (messageIndex == messages.Length)   // disable the timer
                    {
                        messageIndex--;
                        messageTimer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                    }
                }
            }, null, 0, MinSplashTime / (messages.Length * MaxMessageStep));

            try
            {
                initTask = Task.Run(() =>
                {
                    var dataDirectory = Path.Combine(Environment.CurrentDirectory, "datastore");
                    identityStore     = new IncrementalIdentityStore(dataDirectory);
                    folderManager     = new FolderManager(dataDirectory, identityStore);
                    textFileProcessor = new TextFileProcessor(dataDirectory, identityStore);

                    folderManager.TextFileCreated          = (arg) => textFileProcessor.TextFileCreated(arg.FileId, arg.FilePath, arg.OnCompleted);
                    folderManager.TextFileChanged          = (arg) => textFileProcessor.TextFileChanged(arg.FileId, arg.FilePath, arg.OnCompleted);
                    folderManager.TextFileRemoved          = (arg) => textFileProcessor.TextFilesRemoved(new[] { arg.FileId }, arg.OnCompleted);
                    folderManager.MultipleTextFilesDeleted = (arg) => textFileProcessor.TextFilesRemoved(arg.FileIds, arg.OnCompleted);

                    textFileProcessor.StartRequestProcessingLoop();
                    folderManager.StartWatching();
                });
                await Task.WhenAll(Task.Delay(MinSplashTime), initTask);

                var shellForm = new ShellForm(textFileProcessor, folderManager, identityStore);
                StartShellForm(shellForm);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
            }
            finally
            {
                messageTimer?.Dispose();
                animationTimer?.Dispose();
                path?.Dispose();
                brush?.Dispose();
            }
        }