I have a method that runs for a very long time and writes to log files. It's set up like this
public class PSOHelper
{
public PSOHelper(string[] params)
{
//set up params here
}
public async void RunApp(string runType)
{
//long running application that writes to a text file
}
}
Then in the main program I call this method like so:
public async Task<bool> PreparePSOAndRunPSO()
{
string[] params;
//code to fetch the parameters
PSOHelper psoH = new PSOHelper (params)
try
{
await Task.Run(() =>
{
psoH.RunApp(RunConfig.RunMode);
});
return true;
}
catch( Exception ex)
{
Helper.log.Error("exception starting PSO", ex);
return false;
}
}
Now, in my Main method I want to call PreparePSOAndRunPSO and then, in a while loop read from the log that is being written to in RunApp until PreparePSOAndRunPSO finishes. What is the right way for me to do this?
One thing is to change your
async void RunApp(string runType)
method toasync Task RunApp(string runType)
.Now something like this should work.