0
我開始加載每個窗口/窗體的線程,所以沒有凍結。一切工作正常,但問題是當用戶在線程結束之前更改窗口(該線程返回綁定到數據網格的observableCollection)。有沒有辦法來檢測一個線程是否在更改窗口之前運行並殺死它?NHibernate和MVVM多線程
錯誤消息我得到:
NHibernate.Exception.GenericADOEception: could not execute the query.
MySql.Data.MySqlClient.MySqlException: There is already an open DataReader associated with this Connection which must be closed first.
視圖模型代碼:
public GererArticleViewModel(INavigationService navigationService, IMarqueService marqueService, IFormatService formatService, IArticleService articleService)
{
_formatService = formatService;
_marqueService = marqueService;
_articleService = articleService;
_navigationService = navigationService;
LoadedEvent = new RelayCommand(Loaded);
}
#region Commande
public ICommand LoadedEvent { get; private set; }
#endregion
#region Fonction
private void Loaded()
{
_articleService.AsyncRetrieveAll(LoadedCallback);
}
private void LoadedCallback(IList<Article> list)
{
ListeArticles = new ObservableCollection<Article>(list);
}
#endregion
酒店ListeArticles是綁定到DataGrid
NHibernate的服務代碼:
public void AsyncRetrieveAll(Action<IList<Article>> callback)
{
new Thread(() =>
{
var result = _session.Query<Article>().ToList();
DispatcherHelper.UIDispatcher.Invoke(callback, result);
}).Start();
}
對不起我的英語,法語是我的母語。
你的英語肯定比我的法語好! – EkoostikMartin
法語是一種非常難學的語言 – seb