I have a some code:
public MainPage()
{
InitializeComponent();
MyPostRequest.GetDataFromService((result) =>
{
Dispatcher.BeginInvoke(() => { //Update UI from web service});
});
System.Threading.Thread myThread = new System.Threading.Thread(new System.Threading.ThreadStart(MyThread));
myThread.Start();
}
private void MyThread()
{
//do something
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
Dispatcher.BeginInvoke(() =>
{
stopwatch.Stop();
long elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
Debug.WriteLine("time: {0} ms", elapsedMilliseconds);
//update UI
});
}
Basically, the measured time is about 100 ms, but seldom 1000 - 5000 ms. Before you upgrade UI, I check the data in the local database and the data is sampled. I am confused, what exactly is the delay when switching to the UI thread. In what could be the problem?