I've read alot of questions here about accessing labels and UI elements from static methods, but I haven't really found any solution I can apply to my project.
In the main window of my application, I have a method that calls another method, in another class. That method syncronizes some XML readings and stores them to a local file.
This is how I want it to behave:
I call this method (Located in my MainWindow source file) from anywhere inside the namespace:
public static async void UpdateAllLocalFeedsAsync()
{
lblStatusBar.Content = "Working-working etc...";
var result = await ThisFunctionsSyncronizesXmlWithLocalFiles(Parameter);
lblStatusBar.Content = "The job has been done.";
Print some info that tells the user what is about to happen, do the stuff, and tell the user it's been done.
At this moment, everything works smooth as silk, as long as I exclude the lblStatusBar-rows. But as expected, I get the following error when I try to change the content in the label:
Cannot access non-static field 'lblStatusBar' in static context
If I try to make the methods non-static, the async/await abilities seems to fail, requiring them to be static.
I did however find this answer, here on SO...
static void SetTextboxTextSafe(int result)
{
label1.Text = result.ToString();
}
... which I unfortunately did not understand how to apply on a label. My apologies if I'm not being clear enough, but I hope you understand my question.