I'm working on a backup manager for some Quest (critical infrastructure monitoring devices) when running the Code it seems to be running my tasks as its adding them to a task list before calling .WhenAll. then when calling .WhenAll i get null ref exceptions and aggregate Exceptions. I'm using a telnet nuget, you can assume the telnet works as it works on its own and when running this synchronously
I'm new to Async/Await in c#. Ive tried getting rid of the telnet portion and just run the HTTP and vice versa. Ive removed the async Method(runBackupAsync) and run direct to the async class (BackupSingleBoxAsync) no change
(BackupSingleBoxAsync)
private Quest QuestBox = new Quest();
public BackupSingleBoxAsync(Quest q)
{
this.QuestBox.IP = q.IP;
this.QuestBox.User = q.User;
this.QuestBox.Password = q.Password;
this.QuestBox.Type = q.Type;
}
public async Task<Quest> StartAsync()
{
Quest tempQuest = new Quest();
while (QuestBox.User != null && QuestBox.Password != null)
{
if (QuestBox.Type.ToLower().Contains("mini"))
{
HttpDownload getRes = new HttpDownload(QuestBox);
tempQuest = await getRes.Start();
}
else
{
Telnet getRes = new Telnet(QuestBox);
tempQuest = await getRes.Start();
}
}
this.QuestBox.Results = tempQuest.Results;
return QuestBox;
}
(Backup Controller)
GetConfigs config = new GetConfigs(QuestMasterList);
List<Quest> questAterDownload = config.GetAll().Result;
(GET CONFIGS)
public List<Quest> QuestMasterList = new List<Quest>();
public GetConfigs(List<Quest> list)
{
this.QuestMasterList.AddRange(list);
}
public async Task<List<Quest>> GetAll()
{
List<Task<Quest>> task_list = new List<Task<Quest>>();
foreach (var quest in QuestMasterList)
{
task_list.Add(runBackupAsync(quest));
}
await Task.WhenAll(task_list);
List<Quest> tempQuests = new List<Quest>();
foreach (var tsk_rslt in task_list)
{
tempQuests.Add(tsk_rslt.Result);
}
return tempQuests;
}
private async Task<Quest> runBackupAsync(Quest quest)
{
BackupSingleBoxAsync backup = new BackupSingleBoxAsync(quest);
Quest res = backup.StartAsync().Result;
return res;
}
(Quest)
public string IP;
public string User;
public string Password;
public string Type;
public bool Success;
public bool Diff;
public List<string> Results = new List<string>();
I Expect it to return a list of quest box type but instead it gives null ref exceptions and aggregate exceptions