I try to create a thread and manipulate UI controls inside it, then I recived an exception
System.Runtime.InteropServices.COMException: 'The application called an interface that was marshalled for a different thread.
Through searching, I found this is a very common problem, here is one way I have found
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
    {
        // Your UI update code goes here!
    }
);
But this cause another exception
System.InvalidOperationException: 'A method was called at an unexpected time.
I don't know the correct way
private void MessageReceived(string message_content)
{
    InvertedListView.Items.Add(new Message(message_content, DateTime.Now,HorizontalAlignment.Left));
}
static bool flag = true;
Thread thread = new Thread(() =>
{
    FileSystemWatcher watcher = new FileSystemWatcher();
    watcher.Path = "C:\\Users";
    watcher.Filter = "text.txt";
    watcher.NotifyFilter = NotifyFilters.LastWrite;
    watcher.Changed += OnChanged;
    Debug.WriteLine("START!");
    watcher.EnableRaisingEvents = true;
    void OnChanged(object sender, FileSystemEventArgs e)
    {
        if (flag)
        {
            Debug.WriteLine("OnChanged");
            Thread.Sleep(10);
            var lastLine = File.ReadLines(watcher.Path + watcher.Filter, Encoding.UTF8).Last();
            MessageReceived(lastline); // The exception happened here
            Debug.WriteLine(lastLine);
            flag = false;
        }
        else
        {
            flag = true;
        }
    }
});