I've a Windows Form with a ListView control. I have another class "job" which gets instantiated and executed on a separate thread from this form after it is loaded. I want to update ListView control on this Form when some action is being performed by the class.
Code of the Job Class is as under: In the DoJob function I want to update some statuses in the listview control on another windows form
class ConnectToDatabase : Job
{
/// <summary>
/// Counter used to count the number of times this job has been
/// executed.
/// </summary>
private int counter = 0;
public ConnectToDatabase()
{
}
/// <summary>
/// Get the Job Name, which reflects the class name.
/// </summary>
/// <returns>The class Name.</returns>
public override string GetName()
{
return GetType().Name;
}
/// <summary>
/// Execute the Job itself. Just print a message.
/// </summary>
public override void DoJob()
{
Console.WriteLine(string.Format("This is the execution number \"{0}\" of the Job \"{1}\".", counter.ToString(), GetName()));
counter++;
}
/// <summary>
/// Determines this job is repeatable.
/// </summary>
/// <returns>Returns true because this job is repeatable.</returns>
public override bool IsRepeatable()
{
return true;
}
/// <summary>
/// Determines that this job is to be executed again after
/// 1 sec.
/// </summary>
/// <returns>1 sec, which is the interval this job is to be
/// executed repeatadly.</returns>
public override int GetRepetitionIntervalTime()
{
return 10000;
}
}
Currently I solved this issue by making the listview control static in the designer class of the form and accessed it from the class but this approach is not a good practice as designer class is the property of the IDE. What are the best practices to achieve this functionality