Exemplo n.º 1
0
    private void StartProcessing()
    {
        IsProcessing = true;

        // Create a new worker thread that will process the words and place them into loadedWords and letterMappings
        worker = new CBWordDictWorker();
        worker.WordFileText = fileText;
        worker.Type         = typeOfWork;

        switch (typeOfWork)
        {
        case CBWordDictWorker.TypeOfWork.PreProcess:
            worker.PreProcessedStreamWriter = new System.IO.StreamWriter(CBUtilities.PreProcessedFileFullPath);
            worker.CluesStreamWriter        = new System.IO.StreamWriter(CBUtilities.CluesFileFullPath);
            break;

        case CBWordDictWorker.TypeOfWork.Load:
            loadedWords    = new Dictionary <int, List <string> >();
            letterMappings = new Dictionary <int, Dictionary <string, List <string> > >();
            clues          = new Dictionary <string, List <string> >();

            worker.Words          = loadedWords;
            worker.LetterMappings = letterMappings;
            worker.Clues          = clues;
            worker.CluesFileText  = System.IO.File.ReadAllText(CBUtilities.CluesFileFullPath);
            break;
        }

        // Start the thread
        new Thread(new ThreadStart(worker.Run)).Start();
    }
Exemplo n.º 2
0
    /// <summary>
    /// Checks the progress of the thread. After this is called, State will be set to Loaded if the worker thread has finished.
    /// </summary>
    public float CheckProgress()
    {
        float progress = 0f;

        if (IsProcessing)
        {
            // Check if we are waiting for the old thread to stop
            if (waitingForWorkerToStop)
            {
                if (worker.Stopped)
                {
                    waitingForWorkerToStop = false;
                    IsProcessing           = false;
                    worker = null;

                    if (deletePreProcessedFileWhenStopped)
                    {
                        deletePreProcessedFileWhenStopped = false;
                        CBUtilities.DeletePreProcessedFile();
                    }

                    if (clearWhenStopped)
                    {
                        clearWhenStopped = false;
                        Clear();
                    }

                    if (startNewThreadWhenStopped)
                    {
                        startNewThreadWhenStopped = false;
                        StartProcessing();
                    }
                }
            }
            else
            {
                if (worker.Stopped)
                {
                    // Worker thread is done
                    worker       = null;
                    progress     = 1f;
                    IsProcessing = false;
                }
                else
                {
                    progress = worker.Progress;
                }
            }
        }

        return(progress);
    }