Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6188305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:12:34+00:00 2026-05-24T02:12:34+00:00

We are working on a c# windows service using NHibernate which is supposed to

  • 0

We are working on a c# windows service using NHibernate which is supposed to process a batch of records.

The service has to process about 6000 odd records and its taking about 3 hours at present to process these. There are a lot of db hits incurred and while we are trying to minimize these , we are also exploring multithreading options to improve performance.

We are using the UnitOfWork pattern to access the NHibernate session.

This is roughly how the service looks :

public class BatchService
    {
        public DoWork()
        {
           StartUnitOfWork();

           foreach ( var record in recordsToBeProcessed)
           {
              Process(record);
              // Perform lots of db operations
           }

           StopUnitOfWork();
        }
    }

We were thinking of using the Task Parallel Library to try to process these records in batches ( using the Parallel.Foreach () method).
From what I have read about NHibernate so far , we should provide each thread a separate NHibernate session.

My query is how do we supply this ..considering the UnitOfWork pattern which only allows one session to be available.

Should I be looking at wrapping a UnitOfWork around the processing of a single record ?

Any help much appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:12:35+00:00Added an answer on May 24, 2026 at 2:12 am

    The best way is to start a new unitofwork for each thread, use a thread-static contextual session NHibernate.Context.ThreadStaticSessionContext. You must be aware of dettached entities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Overview: I'm working on some windows service using Visual Basic 2010, which deployed on
I'm working with an n-Tier application using WinForm and WCF Engine Service (Windows Service)
I am working on Windows Server 2003 (IIS6), which has two asp.net sites running
I'm pretty sure that a Windows service gets C:\winnt (or similar) as its working
I am working on a windows service application that is supposed to run jobs
I am working on a Windows service which needs to schedule tasks whenever one
I have modified a working Windows service that had always been starting beforehand. After
I am working on a windows service that polls for a connection to a
I'm working on a Windows Service that's having some issues with Thread.Sleep() so I
I have a service, as follows: The most basic (working) CherryPy 3.1 Windows service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.