Having trouble understanding how to run a method from another class in the background.

I am writing a class that will call an exe wait for it to finish and then read data from a CVS file it will then process and put the data into a list of a custom object.

namespace Trav_DV.Services { public interface IRestService { List<DeviceModel> GetDevices(); }

class RestService : IRestService { public List<DeviceModel> GetDevices() { List<DeviceModel> devices = new List<DeviceModel>(); if (File.Exists(GlobalVar.ExePath)) { ProcessStartInfo pInfo = new ProcessStartInfo(); pInfo.Arguments = TravUtilArgs.GetDevices(); pInfo.FileName = GlobalVar.ExePath; Process pStart = new Process(); pStart.StartInfo = pInfo; pStart.Start(); pStart.WaitForExit(); } return devices; } } 

Right now the method doesn't read the output file.

I am trying to figure out how I should handle waiting for this to finish. I have been looking into it and haven't really figured out what I should do. I have been trying to get async await working but I get a warning saying the method has no await operators and will run synchronously. I am unsure what the proper usage for task and async would be when called from another message. How would you handle it? I know I could us a background worker but I would like to better understand Tasks and async/await.

by Mac_Attack18 via /r/csharp

Leave a Reply