I have a while loop in Main() which goes through several methods. Although one method named ScanChanges()
has an if / else statement, in the case of if
, it must jump to Thread.Sleep(10000)
(at the end of the loop).
static void Main(string[] args)
{
while (true)
{
ChangeFiles();
ScanChanges();
TrimFolder();
TrimFile();
Thread.Sleep(10000);
}
}
private static void ChangeFiles()
{
// code here
}
private static void ScanChanges()
{
}
FileInfo fi = new FileInfo("input.txt");
if (fi.Length > 0)
{
// How to Escape loop??
}
else
{
Process.Start("cmd.exe", @"/c test.exe -f input.txt > output.txt").WaitForExit();
}
Make ScanChanges return some value indicating whether you must skip to the end of the loop:
class Program
{
static void Main(string[] args)
{
while (true)
{
ChangeFiles();
bool changes = ScanChanges();
if (!changes)
{
TrimFolder();
TrimFile();
}
Thread.Sleep(10000);
}
}
private static void ChangeFiles()
{
// code here
}
private static bool ScanChanges()
{
FileInfo fi = new FileInfo("input.txt");
if (fi.Length > 0)
{
return true;
}
else
{
Process.Start("cmd.exe", @"/c test.exe -f input.txt > output.txt").WaitForExit();
return false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With