I have this class :
Public class Error
{
public string ErrorMessage { get; set; }
}
public class Test
{
public int Id { get; set; }
public Import ImportResult { get; set; }
public List<Error> Errors { get; set; }
public void Start(object data)
{
object[] obj = data as object[];
string[] importList = { "Item1", "Item2", "Item3", "Item4" };
foreach (var item in importList)
{
object[] obj1 = new object[2];
obj1[0] = item;
obj1[1] = Errors;
this.ImportResult = new Import();
this.ImportResult.StartLongRunningProcess(obj1);//pass each import record to this method
}
}
}
public class Import
{
public int Id { get; set; }
public List<Error> Errors { get; set; }
public void StartLongRunningProcess(object data)
{
object[] datas = data as object[];
string import = datas[0].ToString();
try
{
// here I have along running process
}
// Here I store my error result in above list in long running process
catch (Exception ex)
{
datas[1]. // Here I would like to add record to error list of Test class.
Errors.Add(new Error
{
ErrorMessage = ex.message
});
}
}
}
Now what I am trying to do is I want to pass Error list of class Test as a parameter to StartLongRunningProcess
method and from there I would like to store all error records in Error Variable of Test class.
The reason for doing this is because I have 1 method getCurrentData
which is called every 5 second to get errors record currently running import item.So at the end of all import items I would have list of errors ready for all import item.
public string getCurrentData() //called every 5 seconds to get latest data
{
var data = TestList.FirstOrDefault(x => x.Key == 100).Value;
response = new
{
errors = data.Errors.Select
(er => new
{
//error properties
}).ToList()
}
Parameter of StartLongRunningProcess is object because this method is running on threadpool from my another page that is why I have kept datatype as object for parameter data.
I also cannot make list of import like below :
public List<Import> ImportResults = new List<Import>();