I'm new in C# programming.
I want to write a simple Form application where on a ListView after each action, I will be updated what is going on.
I wrote some code which should do the job.
The application is working good but the update on the ListView not.
namespace ReportingTool
{
public partial class Form1 : Form
{
public static Form1 form;
public Form1()
{
InitializeComponent();
form = this;
WriteToList("1", "Program started");
}
private async void button1_Click(object sender, EventArgs e)
{
WriteToList("2", "Opening Chrome Browser");
PageNavigation driver = new PageNavigation();
await driver.BrowserActions();
WriteToList("3", "Opening TalentLink page");
await driver.GoToTalentLinkPageAsync();
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
public void WriteToList(string id, string action)
{
form.Activate();
ListViewItem x = new ListViewItem(id);
x.SubItems.Add(action);
form.listView1.Items.Add(x);
form.listView1.Refresh();
}
}
}
Thank you for your help.
WriteToList()runs on the UI thread and should work just fine whether it's called from a synchronous or asynchronous event handlerBroweserActions()andGoToTalentLinkPageAsync()methods do?