Re: singleton ienumerable, need to add more...
- From: "David" <david.colliver.NEWS@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 19 Nov 2006 13:17:02 -0000
Hi Marc,
I appear at the moment to be taking a lot of knowledge, to the point where
you gave me the sample code. I felt a little guilty about this, however it
has really helped me along and I have learned one or two things along the
way and it is appreciated.
If I was to rerun the query again, you say to take out the Write Lock. How
would I do that?
I have overloaded the GetFolders method as I want to be able to just do
GetFolders (which would select top level parent), then select specifically
child folders of that parent, so that if need be, I can set up a recursive
loop. This appears to work excellent, but I would like you to cast your eye
over it and tell me if I am missing something, or have made an inefficient
mistake.
public static Folder[] GetFolders()
{
return GetFolders(0);
}
public static Folder[] GetFolders(int ParentFolderID)
{
DataTable ChildDT = DT.Copy(); // This line took me a while to work. I
was doing .Clone() but nothing was happening.
DataRow[] RowView = ChildDT.Select("FolderParent=" + ParentFolderID);
ArrayList ChildFolders = new ArrayList();
foreach (DataRow dr in RowView)
{
ChildFolders.Add(new Folder(dr));
}
ChildFolders.TrimToSize();
syncLock.AcquireReaderLock(Timeout.Infinite);
try
{
return (Folder[])ChildFolders.ToArray(typeof(Folder));
}
finally
{
syncLock.ReleaseReaderLock();
}
}
The only thing I can think of is that I am populating the arraylist quite
early on in the previous code, but with this new method, never getting a
chance to read it... Also, do I need to move the syncLock anywhere in the
GetFolders overload? In fact, as I am creating a new arraylist that will
only be around just for that instance, do I even need the syncLock?
When I am happy with this, then I can do the "ParentFolder" using a similar
method.
Would this code be quite easy to do something like...
GetFolders.GetFolders.GetFolders.GetFolders ? (the point being to try and
get the Great Grandchildren of the current folder... I have some sample
code somewhere to do the multiple dotted thing, so I will see if that can
easily be added.)
Once again, thanks for your help.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"Marc Gravell" <marc.gravell@xxxxxxxxx> wrote in message
news:1163886061.020726.79110@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
obj to DataRow drGood call; my "obj" was just a sampl - your code made it clear that
there was a ctor, but it wasn't shown, so I "failed safe"
I really do apologise for not having enoughNo need to; the only way to obtain useful knowledge is to try things,
knowledge in this area to fix it myself
and you are showing that you *are* giving it a good go, so no apology.
Sometimes people post what amounts to "please do everything; I haven't
even tried"; you have given it fair effort.
1. static classIt will work identically without it; "static class" is just a handy way
of ensuring static semantics at the compiler level, but this can be
done with or without this new modifier
2. ArrayList, 3. ctor, 4. TrimToSizePerfect
The array cast is unfortunately expected when using an ArrayList. There
is an overload to enable this cast:
return (Folder[])folders.ToArray(typeof(Folder));
rerun query etcFine, but for performance I would run the query first (getting the DT),
and then (once complete) take out the write-lock and update the
collection (probably Clear() and re-build from scratch)
foreach questionThe nuicance is supporing the writer in a threaded environment (such as
ASP.NET; *highly* threaded); there are a few tricks, but I think that
they may be a little more troublesome long-term; personally, if I only
needed the data once (i.e. I don't need to loop 3 times), then I would
just use foreach(Folder folder in Folders.GetFolders()) {}.
List vs ArrayListList<T> (not List) is a generic collection type; this means that it is
stronlgy-typed using a template type "T" (that is only decided by the
programmer later): List<Folder> knows that it is means to hold Folder
items, where-as ArrayList only knows about "object". Firstly this makes
it very easy (and safe) to use; as examples, ToArray() returns
Folder[], and folders[0] would return a Folder. It also means that you
cannot *possibly* add an incorrect typed object (such as a string). For
value-types this also avoids boxing etc, making it more efficient.
Marc
.
- Follow-Ups:
- Re: singleton ienumerable, need to add more...
- From: Marc Gravell
- Re: singleton ienumerable, need to add more...
- References:
- singleton ienumerable, need to add more...
- From: David
- Re: singleton ienumerable, need to add more...
- From: Marc Gravell
- Re: singleton ienumerable, need to add more...
- From: David Colliver
- Re: singleton ienumerable, need to add more...
- From: Marc Gravell
- Re: singleton ienumerable, need to add more...
- From: David Colliver
- Re: singleton ienumerable, need to add more...
- From: Marc Gravell
- Re: singleton ienumerable, need to add more...
- From: David Colliver
- Re: singleton ienumerable, need to add more...
- From: Marc Gravell
- Re: singleton ienumerable, need to add more...
- From: David
- Re: singleton ienumerable, need to add more...
- From: Marc Gravell
- singleton ienumerable, need to add more...
- Prev by Date: Re: Stack question
- Next by Date: NotifyIcon DoubleClick also fires Click
- Previous by thread: Re: singleton ienumerable, need to add more...
- Next by thread: Re: singleton ienumerable, need to add more...
- Index(es):
Relevant Pages
|