SoFunction
Updated on 2025-03-06

c# A small program implementation code that restarts regularly page 1/2


private readonly Dictionary<string, bool> cache =
new Dictionary<string, bool>();

private readonly IniFile ini = new IniFile((""));
private bool _flag;
private string day;
private string fHour;
private string fWeek;
private string hour;
private Thread timeThread;


protected override void OnStart(string[] args)
{
Go();
}

protected override void OnStop()
{
StopThread();
}

/// <summary>
/// implement
/// </summary>
public void Go()
{
day = ("yyyy-MM-dd");
fWeek = ("Task", "Week");
fHour = ("Task", "Hour");
RunThread();
}

/// <summary>
/// Execution thread
/// </summary>
private void RunThread()
{
//The thread starts here
_flag = true;
timeThread = new Thread(ThreadTimer);
();
}

/// <summary>
/// Stop the thread
/// </summary>
private void StopThread()
{
_flag = false;
if (timeThread != null) ();
}

/// <summary>
/// Thread method
/// </summary>
public void ThreadTimer()
{
while (_flag)
{
if (fWeek == "") //By day
{
RunBackup();
}
else
{
// By week
if (WeekSwitch(fWeek) == () && WeekSwitch(fWeek) != "")
{
RunBackup();
}
}
}
}

/// <summary>
/// Database list
/// </summary>
private DataTable GetTaskList()
{
DataSet ds = new DataSet();
((""));
return ["DataSet"];
}

private void RunBackup()
{
if (!((""))) return;

day = ("yyyy-MM-dd");

hour = ("HH");
if ((fHour))
{
if (!(day)) (day, false);

if (fWeek != "" && cache[day] == false)
{
if (WeekSwitch(fWeek) == ((day)))
{
StartWork();
cache[day] = true;
}
}
else
{
if (cache[day] == false)
{
StartWork();
cache[day] = true;
}
}
}