Esempio n. 1
0
        public string GoButt(int maxValue)
        {
            var resultText = new StringBuilder();

            for (int trial = 2; trial <= maxValue; trial++)
            {
                bool isPrime = true;
                for (int divisor = 2; divisor <= Math.Sqrt(trial); divisor++)
                {
                    if (trial % divisor == 0)
                    {
                        isPrime = false;
                        break;
                    }
                }
                if (isPrime)
                {
                    resultText.AppendFormat("{0} ", trial);
                    Thread.Sleep(1000);
                }
            }
            PrintInResultLabelDelegate delPrint = new PrintInResultLabelDelegate(Print);

            ResultLabel.Invoke(delPrint, new object[] { resultText.ToString() });
            return(resultText.ToString());
        }
Esempio n. 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Serializer lastSession = new Serializer(entities);

            StopWorkButton.Enabled = false;

            Task.Factory.StartNew(async() =>
            {
                while (running)
                {
                    if (stopwatch.Running)
                    {
                        ResultLabel.Invoke((MethodInvoker) delegate
                        {
                            ResultLabel.Text = stopwatch.Elapsed.ToString("hh':'mm':'ss");
                        });

                        await Task.Delay(50);
                    }
                    else
                    {
                        await Task.Delay(500);
                    }
                }
            });

            aw = new ActiveWindow(ForegroundChanged);
        }
Esempio n. 3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                var dateNow = new List <string>()
                {
                    DateTime.Now.ToString(dateForm)
                };
                var loadSessionsSerialization = new Serializer <Session>(sessions, dateNow);
                sessions = loadSessionsSerialization.ReadEntities();
            }
            catch (FileNotFoundException)
            {
            }

            try
            {
                var categories = new CategoriesManager(dateForm, categoriesFileName);
                categories.ReadCategories();

                foreach (var category in categories.categoriesList)
                {
                    categoriesList.Add(category);
                    categoriesBox.Items.Add(category.categoryName);
                }
            }
            catch (FileNotFoundException)
            {
            }

            categoriesBox.Items.Add(addCat);
            categoriesBox.Items.Add(delCat);

            Task.Factory.StartNew(async() =>
            {
                while (running)
                {
                    if (stopwatch.Running)
                    {
                        ResultLabel.Invoke((MethodInvoker) delegate
                        {
                            ResultLabel.Text = stopwatch.Elapsed.ToString("hh':'mm':'ss");
                        });

                        await Task.Delay(50);
                    }
                    else
                    {
                        await Task.Delay(500);
                    }
                }
            });

            aw = new ActiveWindow(ForegroundChanged);
            StartButton.Enabled    = false;
            PauseButton.Enabled    = false;
            StopWorkButton.Enabled = false;
        }