IDE :: Interaction Of Finalize And Default Implementation Of IDisposable() Interface?
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.
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.
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]
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?
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.
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.
I need to implement the IBindableComponent to the the following code:
Public Class InfragisticsToolStripBindableButton Inherits Infragistics.Win.UltraWinToolbars.ButtonTool Implements IBindableComponent
[CODE]...
1 problem: Warning: event 'Disposed' conflicts with property 'Disposed' in the base class 'DisposableObject' and should be declared 'Shadows'
2 problem: Error: Class 'InfragisticsToolStripBindableButton' must implement 'Property Site As ISite' for interface 'System.ComponentModel.IComponent'. Implementing property must have matching 'ReadOnly' or 'WriteOnly' specifiers.
Why should I implement "IComponent" if I implement "IBindableComponent"?
3 problem: How should I override "Dispose", if it's already implemented in the base class, but is not virtual apparently.
I have been reading about design patterns and application architecture and im told that I should program to an interface instead of implementation. This i understand. So I figured I would start with something small. Never programmed with an interface before. So I want to create an encryption program that will allow the user to select which method to encrypt it with, AES, DPAPI, etc. I started designing the Interface but I am unsure if I am doing this right. [Code] Also, when it comes to the DPAPI implementation, how is the client supposed to supply the Protection Scope? I didn't think this should be in the interface as it only applys to the DPAPI.
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
This may seem like an obvious answer, but I can't seem to find an answer. I have this code in VB.NET[code]...
The problem with this is that in C#, it would seem you have to name the function the same as the interface function you are implementing. How can I call this method EncryptionVB instead of Encryption, but still implement the Encryption property?
Is there any way to include some kind of auto-generated comments as part of implementing an interface? Studio automatically fills the headers for the methods, can I auto-fill some sort of code comments at that same time? (to help remember what each interface method is supposed to do without looking at external documentation.) For example, if I could get the interface's XML Intellisense markup headers to copy from the interface down to the implementation's level.
I am reading a book (ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solution, WROX)The source code is written in C#, but I am a VB guy, so I am giving it a try. Somewhere in the 2nd chapter, there is a Linq to Sql file used that is generated by drag&dropping the DB tables from the Database Explorer. Because some tables have the same type of fields, there is an interface generated called IENTBaseEntity. The writer says its a good practice to implement this interface in another partial class (not the designer.vb file!). The reason for this is that when the LinqToSql file is modified (and regenerated) the changes wont be lost.
In C# this solution is easy to do (i think), but in VB.Net I get an error, because the concerning properties in the LinqToSql file do not append the 'Implement IENTBaseEntity.Property' line. When I press [Enter] after the interface implementation line, VS generates other properties like this
Partial Public Class ENTUserAccount Implements IENTBaseEntity '--->This line results in the error
' This is not the way it should be
Public Property InsertDate1() As Date Implements IENTBaseEntity.InsertDate Get End Get
Private Sub ActivateMe(ByVal active As Boolean) Implements IGraphicControl .ActivateMe compiles.How is possible in VB.NET? A private method can be an interface implementation. VB.NET... a lot of compliments to this language and IDE..
I'm currently pulling HTML data from a database and displaying it in a WebBrowser control in my VB.Net application so that it's correctly rendered. The next step is to print it, but I need to be able to send it to a specific printer rather than the default printer. How can I accomplish this?
public interface IMenuSecurityService { void SetSecurityFlags(List<MenuItem> items); }
I need to implement this interface in a VB.Net class. When I implement the SetSecurityFlags method with the items parameter passed ByVal, it compiles.
Public Sub SetSecurityFlags(ByVal items As List(Of L1.Common.Model.MenuItem)) Implements IMenuSecurityService.SetSecurityFlags ' do some work End Sub
When I try to implement it with the items parameter passed ByRef, I get the following compiler error: Class 'UserRights' must implement 'Sub SetSecurityFlags(items As System.Collections.Generic.List(Of Model.MenuItem))' for interface
Public Sub SetSecurityFlags(ByRef items As List(Of L1.Common.Model.MenuItem)) Implements IMenuSecurityService.SetSecurityFlags ' do some work End Sub
I can't seem to figure this one out. Does VB.Net not support this or am I doing something wrong?
In Visual Studio, when you right-click a method call, you go to the implementation of that method inside a class except if you access this method through an interface: in that case you go to the interface method not to the actual implementation.Is there a way / tips (key shortcut or anything) to access this actual implementation ? Otherwise you are stuck to add some comment just to remember where you did implement it that's really not productive and error prone !
Update: interesting answers but I'm not really satisfied because all are cumbersome. I will give a precise example:
In the code below, when I use the same interface with O in the Class declaration line and the Inherits line, I then get a compiler error when I access the interfaces Year member in both the properties. It says " 'Year' is not a member of 'IRegionYear'." I get the same thing if I use the same class with each Of.
I don't get this error when the interface or class entered for both Of clauses are different. Interface IRegionYear ReadOnly Property Year() As Integer End Interface MustInherit Class RegionYears(Of IRegionYear) [Code] ......
I have a public interface. i have class that implements the interface, how do i make the implementation of interface members internal or private in the implementation class? If i declare an interface internal, how to implement that in an public class?
I'm currently pulling HTML data from a database and displaying it in a WebBrowser control in my VB.Net application so that it's correctly rendered. The next step is to print it, but I need to be able to send it to a specific printer rather than the default printer.
I am creating an xlsx reader / writer for my application (based on OpenXML SDK 2.0). I want to read xlsx files and store the data contained in each row in a DTO/PONO. Further I want to read the xlsx file and then modify it and save it.Now my problem is not with the OpenXML SDK, I can do what I need to do.My problem is on how to structure my components. Specifically I have problems with the polymorphism at the lowest level of a Spreadsheet, the cell.A cell in Excel/OpenXML can have different types of data associated with it. Like a Time, Date, Number, Text or Formula. These different type need to be handled differently when read/written from/to a spreadsheet.I decided to have a common interface for all subtypes like TextCell, NumberCell, DateCell etc.Now when I read the cell from the spreadsheet the Method/Factory can decide which type of cell to create.
Now because the cell is an abstract from the real implementation it does not know / does not need to know of what type it is. For writing / modifying the cell I solve this problem by calling .write(ICellWriter) on the cell I want to persist. As the cell itself knows what type of data it contains, it knows which method of ICellWriter it needs to call (static polymorpism).Writing to the xlsx file is no problem. My problem is, how do I get the data out of my cell into my DTO/PONO without resorting to type checking -> If TypeOf variable is ClassX then doesomething End If. As Methods / Properties have to have different Signatures and differentiating by only using a different return type is not allowed.The holder (collection, in this case a row of a table/spreadsheet) of the objects (refering to the cells) does not know the concrete implementations. So for writing a cell I pass it a Cellwriter. This Cellwriter has overloaded methods like Write(num as Integer), Write(text as String), Write(datum as Date). The cell object that gets this passed to it then calls the Write() method with the data type it holds. This works, as no return value is passed back.After some thinking about the problem I came to realize that it's not possible without reflection or knowledge of what type of cell I am expecting. Basically I was trying to recreate a spreadsheet or something with similar functionality and way too abstract/configurable for my needs.
I am developing a windows forms smart client that uses Fluent Nhibernate 1.1 and NHibernate 3.0 for persistence. Due to legacy code I have had no option but to create a single session that handles all client level CRUD operations. This tends to leave the Nhibernate session in a stale state. So I have made the decision to use QueryOver to eliminate this stale data issue, as I was under the impression that query results were not cached. This doesn't seem to be the happening as the results returned from NHibernate seem to be cached. My question is does the default implementation of QueryOver use some sort of caching when the results are returned?
So I've been doing some research on the singleton factory design pattern, and I am wondering if my example implementation is correct (warning I did get carried away creating animals):
I am trying to re-code a com object that was developed in c++ using vb.net. I have successfully recreated the methods and have been able to register my new vb.net com class with regasm and use it from vb-script. The issue is that the previous class used a coclass with a default interface allowing us to create objects in our vb scripts by simply calling the library.
eg.
Code: dim z set z = createobject("library") my com object requires that i do the following
eg.
Code: dim z set z = createobject("library.interface")
because we do not want to redo all our vb scripts is there a way to have my code function in the same manner as the previous c com object? with out getting into great detail my vb code to create the class looks as follows which is essentially what vb.net provides me. for simplicity I have not added my methods. [Code]
I have an interface that I've defined and am working through a bunch classes that will implement it. I'm noticing that in 95% of the implementations, I'm only changing a few lines of the code, so I'd like to know if it's possible to have my IDE generate a block of code inside of a method upon implementation, much the same as implementing IDisposable.not mark my posts as answered. It is extremely rude. You have no idea if you've answered my question.I WILL come back and mark the ones that are answers, as answers.
I like the default icon the program uses on the form title bar. The icon with the little red yellow and blue colored squares. I would also like to use it as the application build icon so it use it as the icon for the .exe file and shortcuts to the .exe file.I searched a long time and couldn't find the answer. Some said to take a screen-shot of the icon displayed on the screen and crop the image and make an icon that way, but when I tried to use alt-tab with the program running, and press print-screen, the alt button made it take a screen-shot of the currently selected window and not the entire screen, so I couldn't figure out how to get a screen-shot of it at it's full size.
I have a form with buttons, and the user can change the colors of the buttons with the color dialog box for fun:
Button_Play.BackColor = ColorDialog.Color
There is a reset button to put the colors to how they were without any special coloring, but I can't get them to go back to how they originally looked.They go to gray in the middle, instead of the nice shaded blue/gray style. I have tried a few different things:
I am using VB '08 Express on Win XP with the Desktop, Display Properties, Appearance, Windows and Buttons: set to Media Center Style and Color Scheme: set to Energy Blue. how to (with this theme) get the button to look like default after changing the color?
<AcceptVerbs(HttpVerbs.Post)> _ Function Widget(ByVal collection As FormCollection) As ActionResult ... If ... Then
[code]....
I upgraded to ASP.NET MVC 2 Beta and ASP.NET MVC 2 Futures Assembly for Beta and now ToValueProvider() fails with this compile-time error: Interface 'System.Web.Mvc.IValueProvider' cannot be indexed because it has no default property How do I use ModelState.SetModelValue() if not with collection.ToValueProvider()?