0
我有一个Dispatcher,我必须用它来更新我的位图,但是返回行是在调度程序内部的代码完成之前执行的,所以结果并不如预期。在Dispatcher.invoke方法返回后
如何在调度员完成后返回一个值?我不能离开调度员的回报。
下面是我的代码:
public ObservableCollection<FavoriteStruct> LoadMobion()
{
List<FavoriteMobion> results;
using (FavoriteDataContext context = new FavoriteDataContext(connectionString))
{
IQueryable<FavoriteMobion> query = from c in context.TbFavoriteMobion
select c;
results = query.ToList();
}
ObservableCollection<FavoriteStruct> lstFavStr = new ObservableCollection<FavoriteStruct>();
if (results != null)
{
Thread load = new Thread(new ThreadStart(() =>
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
foreach (var rst in results)
{
BitmapImage bi;
bi = new BitmapImage();
bi.UriSource = new Uri("../Images/default_avatar_small.jpg", UriKind.Relative);
lstFavStr.Add(new FavoriteStruct()
{
Opacity = 0.8f,
Status = "../Images/offline.png",
RealID = rst.RealID,
GroupType = rst.GroupType,
MsgStatus = rst.MsgStatus == "" ? "offline" : rst.Path,
Name = rst.Name,
Path = rst.Path == "" ? "" : rst.Path,
Phone = rst.Phone,
Picture = bi
});
}
});
}));
load.Start();
load.Join();
}
return lstFavStr;
}