|
It's kind of an extra check. The world isn't going to end if you don't do the check, but it might add an extra bit of insurance that things aren't going wrong.
You should never access a disposed object, it can cause all kinds of problems. The check is only there to ensure that you don't. Personally, I do the check in _public_ methods, but tend not to bother in properties. Although technically you probably should.
I'd be interested in other people's opinions on this though.
Simon
|
|
|
|
|
And then what do you do if the instance has been Disposed?
"
The primary use of this interface is to release unmanaged resources.
"
When a class doesn't directly use unmanaged resources or a resource that implements IDisposable, then I generally don't implement IDisposable on it. However, implementing IDisposble allows for the class' use in a using statement which is a very handy technique, so in some cases I may implement a Dispose method that does nothing or otherwise leaves the instance in a usable state.
So I don't bother with tracking whether or not Dispose has been called on the instance.
If Dispose has released some resource, then generally the instance's reference will be null and I can check that and either make a new instance or throw an Exception, as appropriate.
|
|
|
|
|
JoeRip wrote: call Dispose() from my destructor
Please make sure you are getting the terminology correct. In C#, the "destructor" is the Dispose() method. If you mean you are calling Dispose() from a method like ~Class() , then you are calling it from a finalizer. If that's the case, you need to triple-check the decision to use a finalizer and make sure that you have everything written correctly as they add a performance penalty to your object and are not trivial to write properly.
JoeRip wrote: Does this mean I also need to test this.disposed in the get/set clauses of my properties?
A lot of this really depends on why you are implementing IDisposable . If you are maintaining some unmanaged resources or other objects that implement IDisposable then you would want to do this test in your public methods and properties. You can simplify this by creating a single helper method that throws an ObjectDisposedException and then just call that as the first line in any of your methods or properties.
If you are using IDisposable simply to get the "using semantics", then you don't need to bother.
You can check this article[^] for more information on how to write finalizers and the dispose pattern as well.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Any one have the Cadlib source code in c# .
Please maile me:muralikumarm76@yahoo.com.
Thank you
..murali
|
|
|
|
|
|
hi simon,
I didn't find it.do u have any sample code using c#
|
|
|
|
|
Seeing as I'm feeling generous, I'll make it easier for you. It's the first one in the results (here[^])
It's not written in C# so there is no C# source code.
If you want to use it from C# you need to learn about Com-Interop. maybe start here[^]. There's also a blog post about it here[^].
Try it. If you get stuck, post what you've done, and what goes wrong, and I'll help you.
Simon
|
|
|
|
|
So I'm building several reports within my application and I wanted to have the functionality that the visual studio report builder gives me. I'm currently using Report Builder v8.0 because I have to construct for the 2.0 framework.
Anyway, here is my problem: I want to do alternating row colors within my table. In the backcolor property I have the function
=iif(RowNumber("DataSet_GetPersonData") Mod 2, "BurlyWood", "White")
If I put this in the backcolor property of the table, the rows inherit only the second color, "white." If I put this in the backcolor property of the row instead, I get the desired look (first row brown, second row white, etc) except the first column doesn't inherit either of the colors. Instead it remains transparent. I've modified the scope several times, using "nothing" and "table 1" instead of "DataSet_GetPersonData" getting the same results each time. What the heck am I doing wrong??
"The shortest distance between two points is under construction"
-Noelie ALtito
|
|
|
|
|
UPDATE:
Turns out when you are developing web applications you should test your product on browsers that don't begin with Mozilla and end in Firefox. Works fine in I.E. I lose.
"The shortest distance between two points is under construction"
-Noelie ALtito
|
|
|
|
|
Hi! I want to write a class for login for the project. I want to know how do i read the username and password from the database. I have a window with two textboxes(username, password) and a submit button.
Thank you
|
|
|
|
|
This page[^] contains the exact information you need...
|
|
|
|
|
You want to Check if the Username and Password Exists in your table, So you can Write a SProc to count the records in the DB and in your class you can have a function that will tell you if the records exists , if it does not , you can return a message to your user that says "invalid Login". Remember dont display to much info, because you might get injected.
Hope this Helps
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Hi there! How can we get the mimetype of a file without using is extension?
I have a lot of .dat file on a server and I wanna know what is the mimetype of each of them. But all I found is fonction/properties related to the extension of the file! It's a no brainer to know that a .xls is an Excel type file
Anyone has a clue?
Thanks.
|
|
|
|
|
No, there's no way to get the mime type without the extension unless you want to try opening the file and try to read it as if it's a file of the desired mime type.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Additionally to what John said, you need to open the file and check the file header (if existent) against a list of known file headers.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Ok, and how to get the file headers?
|
|
|
|
|
Read the first n bytes (e.g. using the BinaryReader ) and see if they match any known header bytes.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Ok, I tought there was some kinda headers like in HTTP request.
I got a list of "headers", but it's mainly a trial and error method, but it seems to work for some mimetypes...so far
|
|
|
|
|
hi,
i want to add vb.net module in c# code..is it possible?..
if yes..please supply a simple example ...
Thanx.....
|
|
|
|
|
Yes it is. Simply write it and reference it just like a normal reference. Once compiled there is no difference between an assembly original written in vb.net and one written in c#
Simon
|
|
|
|
|
Well its Possible, but you should not use Different version of Visual Studio to do that, but i remember i wanted to use a C# function i created in Visual Studio 2005. So what you can do Complile your Project and reference the DLL in the other Project from your vb.net Project and that should work.
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Hello everyone,
When using "int", it is always 32-bit? No matter whether we make build option as Any CPU, x86 and x64?
thanks in advance,
George
|
|
|
|
|
If you want a larger (or smaller) integer, use Int64 or Int16 . An int is as big as the compiler defines it to be.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Thanks John,
Answer to my original question is, int is always 32-bit no matther what platform and build option (Any CPU/x86/x64) is used?
regards,
George
|
|
|
|
|
no. visual c++ 1.2 (and turbo pascal) defined an int as 16-bit. Starting with Visual C++ 2.0, an int was 32 bit.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|