开发者

nhibernate, async loading

开发者 https://www.devze.com 2023-01-09 09:00 出处:网络
I have a question about hibernate. I use different controls in my application (treeview, combobox, ...). I get the content for these controls through nhibernate. The problem is, that it takes a lot of

I have a question about hibernate. I use different controls in my application (treeview, combobox, ...). I get the content for these controls through nhibernate. The problem is, that it takes a lot of time to get the da开发者_运维技巧ta. Drung this time the form is frozen.

I want to load the data in another thread. But i don't know where to put that thread. I'm new at hibernate, maybe you have more experience about that.


This isn't really an NHibernate problem, but rather a .NET Windows Forms threading one. Anyways, on a Forms environment, the easiest way to load all the NHibernate on a background thread would be to use the BackgroundWorker component.

private void LoadData(object sender, EventArgs e)
{
    // This event fires whatever's in DoWork() on a separate thread.
    backgroundWorker1.RunWorkerAsync();

    // Things to do asynchronous operation.
    timer1.Start();
}

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
    // NHibernate loading goes here...
    var employees = Session.CreateCriteria<Employee>();
    combobox1.DataSource = employees;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号