Esempio n. 1
0
        static void Editing()
        {
            var fileWriteHelper = new FileWriteHelper();

            var withWord = true;
            var isAdding = true;
            while (isWorking)
            {
                Thread.Sleep(threadSleepPeriod);
                if (isAdding)
                {
                    for (var i = 0; i < ChangingFilesCount; i++)
                    {
                        fileWriteHelper.AddFileToDirectory(rootLocation, Word, withWord);
                        withWord = !withWord;
                    }
                }
                else
                {
                    fileWriteHelper.DeleteFilesFromDirectory(rootLocation, ChangingFilesCount);
                }

                isAdding = !isAdding;
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            rootLocation = Path.GetTempPath() + "\\" + Guid.NewGuid() + "\\";

            if (!Directory.Exists(rootLocation))
            {
                Directory.CreateDirectory(rootLocation);
            }

            Console.WriteLine("Writing initial files. Please wait.");
            var fileWriteHelper = new FileWriteHelper();
            var withWord = true;
            for (var i = 0; i < InitialFilesCount; i++)
            {
                fileWriteHelper.AddFileToDirectory(rootLocation, Word, withWord);
                withWord = !withWord;
            }

            Console.WriteLine("Writing initial files was finished.");

            editorThread = new Thread(Editing);
            editorThread.Start();

            for (var i = 0; i < SearchingThreadsCount; i++)
            {
                var thread = new Thread(Searching);
                searchingThreads.Add(thread);
                thread.Start();
            }

            var input = string.Empty;
            while (input != "S")
            {
                Console.WriteLine("Write S to stop");

                input = Console.ReadLine();
            }

            isWorking = false;

            Console.WriteLine("Stopping thread-editor");
            editorThread.Join();
            Console.WriteLine("Thread-editor was stopped");

            Console.WriteLine("Stopping threads-searchers");
            foreach (var searchingThread in searchingThreads)
            {
                searchingThread.Join();
            }

            Console.WriteLine("Threads-searchers were stopped");

            new DirectoryInfo(rootLocation).Delete(true);
        }