Problem description
IAsyncAction myCheck = null;
myCheck = ThreadPool.RunAsync(
(IAsyncAction source) =>
{
MyFirstTask();
});
myCheck.Completed = new AsyncActionCompletedHandler(
(IAsyncAction TaskCompletionSource, AsyncStatus status) =>
{
System.Windows.Deployment.Current.Dispatcher.BeginInvoke(
() =>
{
MySecondTask();
});
});
In MyFirstTask()
: I am getting list of files and I'll show them screen using LongListMultiSelector
.
In MySecondTask()
: I have defined one property FileCount
which returns the file count that obtained from MyFirstTask()
. Based on the property FileCount
and files count, I'm showing "No items" text on screen if files count is zero (0) otherwise I'll display all items.
The problem
Before MyFirstTask()
completes fully obtaining all files, MySecondTask()
executes twice, so on first execution we get files count value zero (0). Due to this my UI gets updated with "No items" text... But immediately after 1-2 seconds, MySecondTask()
again triggers the FileCount
property with correct files count and I can see all files on the screen and that text "No items" will disappear.
Please note: This problem happening only when there are a large number of files, so for fewer files this problem is not there... (So, I strongly suspect this is due to sycnronization problems between threads.)
Any suggestions?