473,382 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

DirectoryEntry Disposal Test

I am in a situation in which I am recieving a DirectoryEntry that may or
may not be already be disposed. I need a very fast, (from a code point
of view not necissarily a coding point of view), way of testing if it
has been disposed.

Currently I have:

try
{
string Junk MyDirectoryEntry.Guid.ToString();
}
catch
{
// it has been disposed of, put logic here
}

This is so painfully slow. The 1 line in the try take .00450 seconds and
that of course is not acceptable. Does anyone have a nicer way of
testing for this condition?

-Cam
Nov 18 '05 #1
3 1147
Well, DirectoryEntry has a private bool field called disposed. You could use
reflection to get that out. I'd imagine that'd be faster than throwing an
exception.

And, AFAIK, if the property cache is filled, then getting the guid might not
throw an exception.

-mike
MVP

"cameron" <ca****************@appdepot.com> wrote in message
news:eg**************@TK2MSFTNGP11.phx.gbl...
I am in a situation in which I am recieving a DirectoryEntry that may or
may not be already be disposed. I need a very fast, (from a code point of
view not necissarily a coding point of view), way of testing if it has been
disposed.

Currently I have:

try
{
string Junk MyDirectoryEntry.Guid.ToString();
}
catch
{
// it has been disposed of, put logic here
}

This is so painfully slow. The 1 line in the try take .00450 seconds and
that of course is not acceptable. Does anyone have a nicer way of testing
for this condition?

-Cam


Nov 18 '05 #2
Basically Is see two options:
1) Implement the DirectoryEntry.Disposed eventhandler, in which you set a
flag ( f.i IsDisposed) you can check before using the DirectoryEntry object.
2) Put all your processing in a using block.

Willy.
"cameron" <ca****************@appdepot.com> wrote in message
news:eg**************@TK2MSFTNGP11.phx.gbl...
I am in a situation in which I am recieving a DirectoryEntry that may or
may not be already be disposed. I need a very fast, (from a code point of
view not necissarily a coding point of view), way of testing if it has been
disposed.

Currently I have:

try
{
string Junk MyDirectoryEntry.Guid.ToString();
}
catch
{
// it has been disposed of, put logic here
}

This is so painfully slow. The 1 line in the try take .00450 seconds and
that of course is not acceptable. Does anyone have a nicer way of testing
for this condition?

-Cam

Nov 18 '05 #3
The "real" cache is contained in the unmanaged code portion (ADSI COM
object) as an unmanaged memory resource, but as the DirectoryEntry object is
disposed off, so is the reference to the underlying COM object reference.
Now the (managed) property data only reflects a part of the cached ADSI
data, so it wouldn't be wise to access this data once the object is
disposed.
Therefore, System.ObjectDisposedException is thrown on you when you try to
access the DirectoryEntry object reference.

Willy.
"Michael Giagnocavo [MVP]" <mg*******@Atrevido.net> wrote in message
news:Ox**************@tk2msftngp13.phx.gbl...
Well, DirectoryEntry has a private bool field called disposed. You could
use reflection to get that out. I'd imagine that'd be faster than throwing
an exception.

And, AFAIK, if the property cache is filled, then getting the guid might
not throw an exception.

-mike
MVP

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jessica | last post by:
When I create a single LDAP ActiveDirectory user and use DirectoryEntry.Invoke("SetPassword"...), the user is created and the password is set with no problems. However, when I try to add more...
7
by: cameron | last post by:
I am in a situation in which I am recieving a DirectoryEntry that may or may not be already be disposed. I need a very fast, (from a code point of view not necissarily a coding point of view), way...
2
by: Jay | last post by:
Please excuse the double post if your reader shows this as a new and as a reply. I can only use the web interface and it puts my reply 34 pages in. I am getting an error while trying to do a...
2
by: AbdSol | last post by:
I wanted to know why the output is different & also like to know if C# i can get the user name using DirectoryEntry > find. C# String myADSPath = ("WinNT://"+...
1
by: kenguil | last post by:
I'm hoping that this is the right group to post this to and that someone will have an answer to this. Environment: 1) Laptop joined to domain "foo.com", logged in using cached credentials 2)...
0
by: Mik | last post by:
Hi I am struggling to make a Web site/Web Directory copy work. I am using the System.DirectoryServices to connect to my localhost machine. There I have two web sites: Mysite1 (siteno 1) and...
5
by: ABSMunkee | last post by:
I have a vb.net dll that has two functions: one allows a user to change their password in AD, the second allows the user to view their distinguishedname (based on their samaccountname). Both bind...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.