I'm working with the following code:
----> This is the main class:
---> This is the classed to be invoked
Here the output
White
30/05/2018 17:23:20
% Battery
Black
30/05/2018 17:23:20
% Battery
White
30/05/2018 17:23:20
% Battery
Black
30/05/2018 17:23:20
% Battery
But the time is stop ever at 17:23:20, How can I create a delay between the method writeWhite and writeBlack, in c sharp 4.0(I cant' use the sleep, or await).Thanks.
----> This is the main class:
C#:
class Program {
static void Main()
{
public class a : CalledClassWrite.secondClass
{
public void ThreadOne()
{
for (int i = 0; i < 1000; i++)
{
writeWhiteInk();
System.Threading.Thread.Sleep(2000);
writeBlackInk();
}
}
}
}
}
---> This is the classed to be invoked
C#:
using System.Text;using System.Threading.Tasks;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System.Timers;
namespace CalledClassWrite
{
class secondClass
{
DateTime utc = DateTime.Now;
public void writeWhiteInk()
{
//Create a new file to write
using (StreamWriter writer = new StreamWriter("C:\\Users\\xxxxx\\Desktop\\a.txt", true ))
{
writer.WriteLine("White");
writer.WriteLine("{0}",utc);
//Il valore della batteria sarà di input
writer.WriteLine("% Battery" + Environment.NewLine );
}
}
public void writeBlackInk()
{
//Create a new file to write
TextWriter nf = new StreamWriter(@"C:\\Users\\xxxxx\\Desktop\\a.txt", true);
nf.WriteLine("Black");
nf.WriteLine("{0}",utc);
nf.WriteLine("% Battery\r" + Environment.NewLine);
nf.Close();
}
}
}
Here the output
White
30/05/2018 17:23:20
% Battery
Black
30/05/2018 17:23:20
% Battery
White
30/05/2018 17:23:20
% Battery
Black
30/05/2018 17:23:20
% Battery
But the time is stop ever at 17:23:20, How can I create a delay between the method writeWhite and writeBlack, in c sharp 4.0(I cant' use the sleep, or await).Thanks.