Re: locking objects

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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
.



Relevant Pages

  • Re: multiple instance on Unix
    ... I know the approach to creating a lock file has been around a long time ... The subsequent instances could try to create a directory ... When you're using the filesystem as either a locking ... The first request would be handled and processed, ...
    (comp.lang.python)
  • Re: multiple instance on Unix
    ... I know the approach to creating a lock file has been around a long time ... The subsequent instances could try to create a directory ... When you're using the filesystem as either a locking ... The first request would be handled and processed, ...
    (comp.lang.python)
  • Re: [PATCH 0/7] dlm: overview
    ... >> lock requests involve sending a message to a remote machine and waiting ... >> a request, which is why I'm a bit confused by your question. ... how does oracle's dlm perform for your questions above? ... >> I'd suggest that if some cluster application is using the dlm and has poor ...
    (Linux-Kernel)
  • Re: Static methods in ASP.Net
    ... Do I need to use the lock ... >>request cookie for use by other parts of the application. ... >>static cookie method it could cause problems. ... when or how to use a lock statement in shared methods ...
    (microsoft.public.dotnet.framework.aspnet)
  • [PATCH 1a/7] dlm: core locking
    ... Delivers completion and blocking callbacks to lock holders. ... +** modify, copy, or redistribute it subject to the terms and conditions ... * Used to cancel a pending lock request or conversion. ... * Starts a lockspace with the given name. ...
    (Linux-Kernel)