-4

Dear users & developers,

I have a C# code that writes a variable to a file everytime it changes in value. I want to change it so that it can write every 1 minute (another input to be specified by the user) or so from the time it starts. I am new to data logging, any help/insights regarding the issue would be greatly appreciated.

Thanks AK

Sani Huttunen
  • 23,620
  • 6
  • 72
  • 79

1 Answers1

0

My first tought is to maybe use a System.Threading.Tasks.Task running in the background:

// This is a very crude implementation, but it should serve its purpose.
using System.Threading.Tasks;
public class App
{
    public bool isAppActive = true;
    public static void Main()
    {
        Task mytsk = MyLog();
        Console.ReadKey();
        isAppActive = false;
    }

    public static async void MyLog()
    {
        while (App.isAppActive)
        {
            Thread.Sleep(60000);
            // Write your variable to a file (using an async method and await)
        }
    }
}

... Or maybe using a BackgroundWorker.

TheXDS
  • 88
  • 9