Click here to Skip to main content
15,885,757 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to acheive this in LINQ? PinPopular
Pete O'Hanlon24-May-11 2:23
mvePete O'Hanlon24-May-11 2:23 
GeneralRe: How to acheive this in LINQ? Pin
Groulien24-May-11 2:27
Groulien24-May-11 2:27 
GeneralRe: How to acheive this in LINQ? Pin
Pete O'Hanlon24-May-11 2:28
mvePete O'Hanlon24-May-11 2:28 
GeneralRe: How to acheive this in LINQ? Pin
John-ph24-May-11 2:41
John-ph24-May-11 2:41 
GeneralRe: How to acheive this in LINQ? Pin
Pete O'Hanlon24-May-11 2:42
mvePete O'Hanlon24-May-11 2:42 
AnswerRe: How to acheive this in LINQ? Pin
Sanjay J Patolia25-May-11 2:22
Sanjay J Patolia25-May-11 2:22 
AnswerRe: How to acheive this in LINQ? [modified] Pin
Subin Mavunkal25-May-11 3:12
Subin Mavunkal25-May-11 3:12 
QuestionIDisposable and CA2000 warning during Vs2010 Code Analysis. Pin
gumi_r@msn.com24-May-11 1:32
gumi_r@msn.com24-May-11 1:32 
Hi all,

I need some advice here, I hope somebody can help me.

I have the following class structure (simplified):

public class Bar: IDisposable {...}

public abstract class FooBase: IDisposable
{
  Bar bar;
  bool disposed;

  internal FooBase(Bar bar)
  {
    this.bar=bar;
  }

  public void Dispose()
  {
    if (!this.disposed)
    {
      this.bar.Dispose(true);
      GC.SupressFinalize(this);
      this.disposed = true;
    }
  }

  protected void Dipose(bool disposing)
  {
    if (disposing)
    {
      this.bar.Dispose();
    }
  }
}

public FooA: Foo {...}
public FooB: Foo {...}

public static class FooProvider
{
   public static FooA GetFooA()
   {
     Bar bar = new Bar();
     ...
     return new FooA(bar);
   }

   public static FooB GetFooB()
   {
     Bar bar = new Bar();
     ...
     return new FooB(bar);
   }

   ...
}


When I run Code Analysis on this, I get Warnings CA2000 on all 'CreateFooX()' methods of the FooProvider class. This warning gives the following message: "Microsoft. Reliability: In method 'FooProvider.GetFooX()', call System.IDisposable.Dispose on object 'bar' before all references to it are out of scope."

Microsoft recommends to never supress this warning but I'm not really sure its warning about a real problem in the code. True that 'bar' is not disposed before going out of scope in whatever 'CreateFooX()' method we consider but a reference to it lives on in the 'FooX' object which eventually will get disposed and will in turn take care of disposing 'bar'.

Am I understanding something wrong about how the Dispose pattern should work and I have some fundamental flaw in my code or should I just supress this warning?

Thanks for any advice.
AnswerRe: IDisposable and CA2000 warning during Vs2010 Code Analysis. Pin
Subin Mavunkal24-May-11 2:23
Subin Mavunkal24-May-11 2:23 
GeneralRe: IDisposable and CA2000 warning during Vs2010 Code Analysis. Pin
Pete O'Hanlon24-May-11 2:27
mvePete O'Hanlon24-May-11 2:27 
GeneralRe: IDisposable and CA2000 warning during Vs2010 Code Analysis. Pin
gumi_r@msn.com24-May-11 2:39
gumi_r@msn.com24-May-11 2:39 
GeneralRe: IDisposable and CA2000 warning during Vs2010 Code Analysis. Pin
Subin Mavunkal24-May-11 2:46
Subin Mavunkal24-May-11 2:46 
GeneralRe: IDisposable and CA2000 warning during Vs2010 Code Analysis. Pin
Pete O'Hanlon24-May-11 2:48
mvePete O'Hanlon24-May-11 2:48 
GeneralRe: IDisposable and CA2000 warning during Vs2010 Code Analysis. [modified] Pin
gumi_r@msn.com24-May-11 3:28
gumi_r@msn.com24-May-11 3:28 
GeneralRe: IDisposable and CA2000 warning during Vs2010 Code Analysis. Pin
Subin Mavunkal24-May-11 3:40
Subin Mavunkal24-May-11 3:40 
GeneralRe: IDisposable and CA2000 warning during Vs2010 Code Analysis. Pin
DaveyM6924-May-11 23:40
professionalDaveyM6924-May-11 23:40 
QuestionBar Chart In crystal Report Pin
Member 793274523-May-11 22:19
Member 793274523-May-11 22:19 
QuestionUsing Wild Character _ [modified] Pin
Member 455049323-May-11 5:34
Member 455049323-May-11 5:34 
AnswerRe: Using Wild Character _ Pin
Luc Pattyn23-May-11 5:55
sitebuilderLuc Pattyn23-May-11 5:55 
GeneralRe: Using Wild Character _ Pin
Member 455049324-May-11 0:30
Member 455049324-May-11 0:30 
GeneralRe: Using Wild Character _ [modified] Pin
Luc Pattyn24-May-11 0:56
sitebuilderLuc Pattyn24-May-11 0:56 
GeneralRe: Using Wild Character _ Pin
Pete O'Hanlon24-May-11 1:03
mvePete O'Hanlon24-May-11 1:03 
GeneralRe: Using Wild Character _ Pin
Luc Pattyn24-May-11 1:20
sitebuilderLuc Pattyn24-May-11 1:20 
AnswerRe: Using Wild Character _ Pin
Mycroft Holmes23-May-11 14:07
professionalMycroft Holmes23-May-11 14:07 
GeneralRe: Using Wild Character _ Pin
Member 455049324-May-11 0:18
Member 455049324-May-11 0:18 

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.