Hello Everyone. This is my first post here.
I'm having a very weird issue using Timers.
My elapsed event isn't firing ; when it fires its completely random, not according to the interval i set.
I already tried to drag the timer from the toolbox to the form, creating it manually on the STA Thread, now i'm trying to create it under Form1.cs ...behavior is the same.
I truly don't know whats going on. It was working a few hours before.
Any help is appreciated. THanks !
Code below:
I'm having a very weird issue using Timers.
My elapsed event isn't firing ; when it fires its completely random, not according to the interval i set.
I already tried to drag the timer from the toolbox to the form, creating it manually on the STA Thread, now i'm trying to create it under Form1.cs ...behavior is the same.
I truly don't know whats going on. It was working a few hours before.
Any help is appreciated. THanks !
Code below:
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
namespace DI_Plot_2018
{
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
FileSystemWatcher InputFileWatcher;
FileProcessor TIFFProcessor;
Timer timer1;
LoadInternalSettings InternalSettings;
int counter;
public RadForm1()
{
InitializeComponent();
InternalSettings = new LoadInternalSettings();
counter = Int32.Parse(InternalSettings.Timer);
timer1 = new Timer();
TIFFProcessor = new FileProcessor();
LoadControls(InternalSettings);
}
private void TimerStart()
{
timer1.Enabled = true;
timer1.Interval = counter * 1000;
timer1.Tick += new EventHandler(SecondElapsed);
timer1.Start();
}
private void SecondElapsed(object sender, EventArgs e)
{
counter--;
TimerTextBox.Text = counter.ToString();
if (counter <= 0)
{
TIFFProcessor.TriggerWork();
TimerReset();
}
}
private void FileCreated(Object sender, FileSystemEventArgs e)
{
JobDetails jobInfo = new JobDetails(TIFFProcessor.fileNamesQueue.Dequeue());
if (TIFFProcessor.JobFilesAndInfoDictionary.ContainsKey(jobInfo.JobNameWithoutColor))
{
TIFFProcessor.JobFilesAndInfoDictionary[jobInfo.JobNameWithoutColor].Add(e.FullPath);
}
else
{
TIFFProcessor.JobFilesAndInfoDictionary.Add(jobInfo.JobNameWithoutColor, new List<string>() { e.FullPath });
}
TimerReset();
}
private void TimerReset()
{
timer1.Stop();
TimerStart();
}
private void ButtonChangedEventHandler(object sender, EventArgs e)
{
Telerik.WinControls.UI.RadButton bt = sender as Telerik.WinControls.UI.RadButton;
string buttonName = (String)bt.Name;
SwitchButtonImage buttonImageSwitch;
switch (buttonName)
{
case "StartButton":
{
InputFileWatcher = new FileSystemWatcher(InputFolderTextBox.Text);
InputFileWatcher.Created += new FileSystemEventHandler(FileCreated);
InputFileWatcher.Filter = "*.tif";
InputFileWatcher.EnableRaisingEvents = true;
StopButton.Enabled = true;
StartButton.Enabled = false;
TimerStart();
break;
}
case "StopButton":
{
InputFileWatcher.EnableRaisingEvents = false;
timer1.Stop();
StopButton.Enabled = false;
StartButton.Enabled = true;
break;
}
case "ImageRotationButton":
{
buttonImageSwitch = new SwitchButtonImage(ImageRotationButton, "ImageRotationIndex");
break;
}
case "ImageOrientationButton":
{
buttonImageSwitch = new SwitchButtonImage(ImageOrientationButton, "ImageOrientationIndex");
break;
}
case "InputFolderBrowseButton":
{
InputFolderTextBox.Text = new ItemSaveToConfig.SelectFolderSaveProperty(InputFolderTextBox.Text, "Select the input folder", "InputFolder").folderSelect;
break;
}
case "OutputFolderBrowseButton":
{
OutputFolderTextBox.Text = new ItemSaveToConfig.SelectFolderSaveProperty(OutputFolderTextBox.Text, "Select the output folder", "OutputFolder").folderSelect;
break;
}
}
}
private void LoadControls(LoadInternalSettings Settings)
{
InputFolderTextBox.Text = InternalSettings.InputFolder;
OutputFolderTextBox.Text = InternalSettings.OutputFolder;
NumberOfZonesTextBox.Text = InternalSettings.NumberOfZones;
FirstZoneWidthTextBox.Text = InternalSettings.FirstZoneWidth;
LastZoneWidthTextBox.Text = InternalSettings.LastZoneWidth;
ZoneAreaWidthTextBox.Text = InternalSettings.ZoneAreaWidth;
ZoneAreaHeightTextBox.Text = InternalSettings.ZoneAreaHeight;
ZoneWidthTextBox.Text = InternalSettings.ZoneWidth;
TimerTextBox.Text = InternalSettings.Timer;
ZoneWidthTextBox.Text = InternalSettings.ZoneWidth;
var RotatePreview = new SwitchButtonImage(ImageRotationButton, "ImageRotationIndex");
var OrientationPreview = new SwitchButtonImage(ImageOrientationButton, "ImageOrientationIndex");
}
private void TextBoxChangedEventHandler(object sender, EventArgs e)
{
Telerik.WinControls.UI.RadTextBox TxtBx = sender as Telerik.WinControls.UI.RadTextBox;
string TxtName = TxtBx.Name;
switch (TxtName)
{
case "NumberOfZonesTextBox":
{
NumberOfZonesTextBox.Text = new ItemSaveToConfig.ChangeAndSaveTextBox(NumberOfZonesTextBox.Text, "NumberOfZones", false).TextToApply;
break;
}
case "ZoneWidthTextBox":
{
ZoneWidthTextBox.Text = new ItemSaveToConfig.ChangeAndSaveTextBox(ZoneWidthTextBox.Text, "ZoneWidth", false).TextToApply;
break;
}
case "FirstZoneWidthTextBox":
{
ZoneWidthTextBox.Text = new ItemSaveToConfig.ChangeAndSaveTextBox(FirstZoneWidthTextBox.Text, "FirstZoneWidth", false).TextToApply;
break;
}
case "LastZoneWidthTextBox":
{
ZoneWidthTextBox.Text = new ItemSaveToConfig.ChangeAndSaveTextBox(LastZoneWidthTextBox.Text, "LastZoneWidth", false).TextToApply;
break;
}
}
}
private void RadForm1_FormClosed(object sender, FormClosedEventArgs e)
{
Properties.Settings.Default.Timer = TimerTextBox.Text;
Properties.Settings.Default.Save();
//WaitingTimer.Stop();
Environment.Exit(0);
}
}
}