Click here to Skip to main content
15,891,184 members
Home / Discussions / C#
   

C#

 
GeneralRe: GridView FindControl LINQ Update Pin
RickSharp14-Feb-13 6:43
RickSharp14-Feb-13 6:43 
GeneralRe: GridView FindControl LINQ Update Pin
Richard MacCutchan14-Feb-13 6:58
mveRichard MacCutchan14-Feb-13 6:58 
GeneralRe: GridView FindControl LINQ Update Pin
RickSharp14-Feb-13 10:31
RickSharp14-Feb-13 10:31 
GeneralRe: GridView FindControl LINQ Update Pin
RickSharp14-Feb-13 13:28
RickSharp14-Feb-13 13:28 
QuestionC# Cannot access a disposed object Pin
classy_dog13-Feb-13 8:06
classy_dog13-Feb-13 8:06 
AnswerRe: C# Cannot access a disposed object Pin
Pete O'Hanlon13-Feb-13 8:13
mvePete O'Hanlon13-Feb-13 8:13 
AnswerRe: C# Cannot access a disposed object Pin
jschell13-Feb-13 10:15
jschell13-Feb-13 10:15 
QuestionIDisposable spread Pin
Orjan Westin13-Feb-13 2:45
professionalOrjan Westin13-Feb-13 2:45 
When reading about IDisposable, I get the impression that the consensus is that once you introduce it, everything that's even heard about it need to be made IDisposable too. Can this really be correct?

I have a class DriverWrapper that holds an IntPtr to a DLL with a C interface. This class is IDisposable, and implements the standard Dispose pattern, with a finaliser. It also has a number of abstract functions, some delegate definitions, and a helper function to get a delegate from the loaded DLL.

From this class, I derive some other classes, which implements the abstract functions by creating delegates to DLL functions. (The reason for this is that I have three related DLLs, all doing effectively the same thing to different bits of hardware, so to a user in the application it makes sense that they all have the same, shared interface. Unfortunately, the DLLs have different names, and in some cases different signatures, for their functions.)

Now, the derived classes are already IDisposable from DriverWrapper, but if they only hold delegates, which aren't IDisposable themselves, is there any need to override Dispose(bool) in these? I think not, but I'm no expert on C#.

(Oh, and I'm not concerned with the using idiom, as these will be alive throughout the lifetime of their owner. Neither am I interested in whether I should implement it in case I will at some future point have a managed and disposable member, or hypotheticals like that.)

Next question:
There is an abstract base class Model which takes a DriverWrapper as a constructor parameter, and takes ownership of it. The classes derived from this only override one function, and are just meant to provide different types of DriverWrapper-derived classes. I'll need to have access to the DriverWrapper for the whole lifetime of the Model.

C#
abstract class Model
{
  DriverWrapper theDriver;

  Model(DriverWrapper driver)
  {
    theDriver = driver;
  }
  ...
}

class DriverWrapper : IDisposable
{ 
  ~DriverWrapper()
  
  void Dispose()
  
  void Dispose(bool)
}

class DriverA : DriverWrapper
{ ... }

class DriverB : DriverWrapper
{ ... }

class DriverC : DriverWrapper
{ ... }

class ModelA : Model
{
  public ModelA()
  : base (new DriverA())
  {}
}


Would Model have to be IDisposable? Surely the DriverWrapper is now managed, and will be tidied away when the Model is? If not, would ModelA-C need to override Dispose even if they have no further data?

(Honestly, at times like this I really miss RAII and typedefs from C++)
AnswerRe: IDisposable spread Pin
DaveyM6913-Feb-13 4:52
professionalDaveyM6913-Feb-13 4:52 
AnswerRe: IDisposable spread Pin
Keith Barrow13-Feb-13 5:13
professionalKeith Barrow13-Feb-13 5:13 
GeneralRe: IDisposable spread Pin
PIEBALDconsult13-Feb-13 17:46
mvePIEBALDconsult13-Feb-13 17:46 
GeneralRe: IDisposable spread Pin
N a v a n e e t h13-Feb-13 18:59
N a v a n e e t h13-Feb-13 18:59 
GeneralRe: IDisposable spread Pin
Orjan Westin13-Feb-13 22:33
professionalOrjan Westin13-Feb-13 22:33 
AnswerRe: IDisposable spread Pin
N a v a n e e t h13-Feb-13 18:56
N a v a n e e t h13-Feb-13 18:56 
AnswerRe: IDisposable spread Pin
BobJanova13-Feb-13 23:54
BobJanova13-Feb-13 23:54 
Questionpropertygrid double click events Pin
Jone Cunha13-Feb-13 0:56
professionalJone Cunha13-Feb-13 0:56 
AnswerRe: propertygrid double click events Pin
Richard MacCutchan13-Feb-13 1:14
mveRichard MacCutchan13-Feb-13 1:14 
GeneralRe: propertygrid double click events Pin
Jone Cunha13-Feb-13 1:24
professionalJone Cunha13-Feb-13 1:24 
GeneralRe: propertygrid double click events Pin
Richard MacCutchan13-Feb-13 1:44
mveRichard MacCutchan13-Feb-13 1:44 
GeneralRe: propertygrid double click events Pin
Jone Cunha13-Feb-13 1:53
professionalJone Cunha13-Feb-13 1:53 
GeneralRe: propertygrid double click events Pin
Richard MacCutchan13-Feb-13 3:16
mveRichard MacCutchan13-Feb-13 3:16 
GeneralRe: propertygrid double click events Pin
Jone Cunha13-Feb-13 4:45
professionalJone Cunha13-Feb-13 4:45 
GeneralRe: propertygrid double click events Pin
Richard MacCutchan13-Feb-13 5:38
mveRichard MacCutchan13-Feb-13 5:38 
GeneralRe: propertygrid double click events Pin
Jone Cunha13-Feb-13 7:32
professionalJone Cunha13-Feb-13 7:32 
QuestionEnevts in MVC application. Need some Help. Pin
plywoods12-Feb-13 21:09
plywoods12-Feb-13 21:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.