Re: locking objects
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Wed, 28 Dec 2005 12:39:14 -0000
Pohihihi <noemail@xxxxxxxxxxx> wrote:
> Basically I am creating thread to access db and load a dataset but the part
> when dataset is filled i am putting a lock (in case a next request).
Note that if this is within a Windows Forms app and the dataset is
bound to a control, you should only do the filling within the UI
thread.
> this is
> happening when user scroll through months by clicking month calendar to see
> data related to date. now I can't load few months either side to save some
> data access as there are tons of records and it will eat big amount of
> memory on client to hold that data. so what I do is to handle change event
> and fill the dataset with information for visible month.
So are you creating the new thread within the change event?
> but it is possible
> that user keep on clicking month to scroll to next month. one thing i am
> thinking is that to wait before accessing db to be sure that user is not
> clicking any more but then question comes is how much time to wait. better
> option for now is that i load data anyways. so for that accessing db part
> comes as thread for every request (a new thread every request). now this
> might create problem of its own in case delay is too long and too many
> threads are holding in memory. bottom line is what could be a better
> option.
Well, if you're using a SqlCommand, you could cancel the current
command if one is executing when the user clicks. That's the most
efficient way of doing things without waiting to see if there are more
clicks coming.
As Truong said, the lock statement itself doesn't have a timeout.
However, if you want locking with timeouts, it's quite possible to do
it - see http://www.pobox.com/~skeet/csharp/threads/alternative.shtml
I'm hoping to upload a new version of MiscUtil with deadlock detection
in the next day or two - the code is written, it just needs potentially
renaming and documenting :)
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: locking objects
- From: Pohihihi
- Re: locking objects
- References:
- locking objects
- From: Pohihihi
- Re: locking objects
- From: Jon Skeet [C# MVP]
- Re: locking objects
- From: Pohihihi
- locking objects
- Prev by Date: Re: how do you debug this
- Next by Date: Re: Change default encoding
- Previous by thread: Re: locking objects
- Next by thread: Re: locking objects
- Index(es):
Relevant Pages
|