C# - When Should Implement IDisposable
Mar 12, 2010
What is the best practice for when to implement IDisposable? Is the best rule of thumb to implement it if you have one managed object in the class, or does it depend if the object was created in the class or just passed in? Should I also do it for classes with no managed objects at all?
View 6 Replies
ADVERTISEMENT
Jul 19, 2010
i may be misunderstanding this but on MSDN i believe it says that it is good practice to implement the Dispose destructor in every class you write. should i (do you) really implement the IDisposable interface with every class i write? also, is the proper syntax for implementing an interface to put the "Implements" keyword on the line after the "class" declaration? i put it on the same line as "class" and I got an error.when coding the method implemented by the interface, is it mandatory to follow this syntax, as an example: Public Sub Dispose() Implements System. IDisposable. Dispose.
View 3 Replies
Apr 21, 2009
Recently I needed to compare a suggested pattern for IDisposable and object finalization with the auto-generated one we which VS2005/VB.NET provide. We have used the auto-generated one a fair bit, but after looking it the two side by side I had a number of questions about the VB.NET implementation..
[Code]...
Overall I am confused by the supposed added value of having an extended code-path that executes when Dispose() is called explicitly(as opposed to having a common path that is executed regardless of whether or not Dispose() was called explicitly). how it does anything other than delay the actual release of managed resources if Dispose() isn't called directly. In essence it seems to only work to make the managed resources unreachable in the object graph, orphaning them until the 2nd GC run rather than freeing them at a point where they are known to be no longer needed.
View 3 Replies
Oct 20, 2009
I am a budding MCTS so I am not a 100% sure of whether I am correct in this instance.I am looking through a windows forms application created by a developer who has left our company some time ago. Within the code I have found a custom form derived from the standard form baseclass which explicity implements IDisposable.The custom form does not call any COM object or do any file IO operations and has only one database call which is closed and disposed off in the method that calls it. However within the code of the form there is the following,[code].....
Looking at this am I right in thinking that this should be removed including the implements IDisposable line at the top of the form since,
1. The listeners collection will go out of scope when the form does as the collection only references listener objects (which do not implement IDisposable).
2. The controls do not explicitly need disposing, since when the form goes out of scope this will be done anyway.
View 4 Replies
Feb 6, 2011
In cases where Using can't be used because IDisposable is not implemented, is the following code an OK practice for With/End With? Would this cause a memory leak or would it be better to set an instance variable and then set it to nothing?
With New System.IO.FileInfo(sFileName)
' Do some work
End With
View 3 Replies
May 21, 2009
I have been working on this for a while now. And I am still confused about some issues. My questions below
1) I know that you only need a finalizer if you are disposing of unmanaged resources. However, if you are using managed resources that make calls to unmanaged resources. Would you still need to implement a finalizer?
2) However, if you develop a class that doesn't use any unmanged resources directly or indirectly and you implement the IDisposable so that clients of your class can use the 'using statement'. Would it be acceptable to implement the IDisposable just so that clients of your class can use the using statement?
[Code]...
View 4 Replies
Mar 8, 2009
I implemented IDisposable into one of my classes, but don't know if I did it correctly. Can someone tell me what will be cleared from memory and what will remain after calling .Dispose on an instance of this class? [Code]
View 5 Replies
Dec 30, 2009
just wondering if we could change the implementation functino of IDisposable.Dispose to a private. because the default i've got something like this:
[Code]...
Protected Overridable Sub Dispose(ByVal disposing As Boolean) or could i take away the the Protected Overridable and replace it with a Private access modifier?
View 9 Replies
Jan 25, 2010
I'm using the RegisterHotkey and UnregisterHotkey functions
Code:
<DllImport("user32.dll")> _
Private Shared Function RegisterHotKey(ByVal hWnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As UInteger, ByVal vk As UInteger) As Boolean
[CODE]...
I have a Hotkey class that is (should be) responsible for calling UnregisterHotkey. I want to take it out of the users' hands to ensure that UnregisterHotkey will always be called when the object is destroyed. Would that be IDisposable or something else?
View 1 Replies
Apr 20, 2009
I am comparing an alternative Dispose pattern to VS2005's default implementation. In doing the comparison I have found several uncertainties with the default pattern which have raised a handful of questions related to sub-class implementations and object Finalization.
[Code]...
View 1 Replies
Aug 10, 2010
Is it possible to automatically insert a Code Snippet when an interface is implemented? If so, how do you do it? I am looking for something similar to when you implement IDispoable in VB.[code]This will be used by web forms when transfering parameters from one page to the next using Server.Transfer
View 1 Replies
Mar 14, 2011
How to implement such a feature in vb.net??
View 3 Replies
Apr 5, 2012
We have a vb.net application where we have implemented multithreading. We determined that we need to either implement .net remoting or WCF. After researching remoting in .NET on MSDN, Microsoft considers remoting legacy for .NET framework 4.0 and recommends using WCF instead. My question is: can we implement WCF functionality into our VB.NET application or do we need to rewrite the app from the ground up in WCF?
View 1 Replies
Sep 1, 2010
I have a program that I would like to implement using Threading.I wand to load a form that takes a couple of minutes to open using threading.Here is my code
Imports System.Threading
Public Class frmAdjustments
Function LaunchForm() As Integer[code].....
I am new to .net programming and could use any suggestions you may have. I'm trying to grasp the concept of multithreading apps and would like to have both my main form (Adjustments) and the (frmNewAdjustments) form to load concurrently.Here is the error I receive with the code above: Overload resolution failed because no accessible 'New' can be called with these arguments:
View 3 Replies
Sep 3, 2010
How would you create an extension method which enables me to do the following (warning: exteme pseudo-code)...
class FooBar
{
Int32 Foo { get; set; }
String Bar { get; set; }
}
new FooBar().With(fb => new Func<FooBar, Object>(instance =>
[Code]...
View 5 Replies
Mar 13, 2011
This is just a Translation question. But how do you write a the following C# code in vb.net My problem is that i don't know how to rewrite the this part of the generic T. C# code i want to translate
public static void ShouldEqual<T>(this T actualValue, T expectedValue) {Assert.AreEqual(expectedValue, actualValue); }
[Code]...
View 1 Replies
Aug 7, 2009
I am implementing a tracing mechanism myself. Now what I'd like to know is what is the best way to implement this mechanism(I mean, the architecture).[code]But then I saw there is an TraceListener class that let's me implement Write and WriteLine methods. The big drawback is that both those methods allow only strings as arguments, and I'd want to be able to send a lot more info than strings. What should I do? Maybe my first ideia is the best?I do know there are a lot of tracing mechanisms like PostSharp and so, I'm just doing this for learning purposes!
View 1 Replies
Mar 9, 2012
My Questions are: Is is possible to implement a bitboard in vb.net? Tutorial/Reference to do bitboard in VB?
C# answers are acceptable because it's not that hard to translate.
View 5 Replies
Aug 4, 2010
In .net (c# or vb) expressions, how would you implement SQL's handy IN() functionality?i.e. value in (1, 2, 4, 7)rather than:
value = 1 or value = 2 or value = 4 or value = 7
There are obviously many ways, I'm looking for the most clean and simple!
View 7 Replies
Aug 7, 2009
I am trying to implement an interface defined in IDL, in a vb.net class here is the idl
interface IEmissaryRoot : IDispatch {
id(0x68030000), propget]
out, retval] IActivityCol** );
[code]....
View 3 Replies
Jan 14, 2012
i am using code to the value textbox2.text in the report and using the code like below [code]the textbox2 take various values in run time but when i run the code it display only the final value intermediated values are not displayed the whole situation is as follows.[code]
View 1 Replies
Aug 12, 2011
I would like to use regex for a txt file as follows. What I want to do is to get the whole text if CRC is other than 00000000. The content of the file below has 2 blocks of data below. And I should get the second one after the regex operation.
[Code]...
View 3 Replies
Jun 18, 2010
I guess Blowfish is not included in .net class library.how to implement it,,there are any sample code.? ive already try but still have a trouble to encrypt data without padding. [code] the original source from schneier that implement with vb6 we can encrypt data with or without padding.its mean we can encrypt data in 1 block that contents less than 8 bytes.
View 8 Replies
Feb 26, 2010
How to implement Blowfish in VB 6 and VB.net
View 1 Replies
Jun 19, 2010
how to implement DLLGetVer written in vb.net? I currently have tried the following code but when I try the fucntion, I get Unable to find an entry point named 'DLLGetVersion' in DLL 'msi.dll'.
[Code]...
View 4 Replies
Nov 23, 2010
how to implement dos printing from vb.net?
View 1 Replies
May 31, 2010
How can I implement the next vbs code in C#:[code]
View 11 Replies
Jun 22, 2010
[TEX]Hello[/TEX] How do i use truncate in vb 2008?my database its in Access and i want to implement a truncate table in vb but i don't know how to do it.
View 1 Replies
Apr 22, 2010
Can anyone help me with a way to implement typedef in vb2010, because I see it helpfull way to define types.
View 2 Replies
Jul 25, 2010
I'm trying to assign a datasource to a ComboBox control during runtime. When I do so, I get the attached message. [Code] I want to learn how to use an Interface. The error message is suggesting using an IList. How would I do this.
View 2 Replies