5 Replies - 16250 Views - Last Post: 25 January 2009 - 03:09 PM Rate Topic: -----

#1 turtleC++  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 123
  • Joined: 07-May 08

how to add Dispose to Class library?

Post icon  Posted 25 January 2009 - 01:39 PM

I just lean how to create Class library for my own convinience some of the functions, but how can I add dispose function to my class library?

can anyone suggest me how to do it?
Is This A Good Question/Topic? 0
  • +

Replies To: how to add Dispose to Class library?

#2 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: how to add Dispose to Class library?

Posted 25 January 2009 - 01:42 PM

Try looking at this MSDN article:

http://msdn.microsof...ftw(VS.80).aspx
Was This Post Helpful? 1
  • +
  • -

#3 turtleC++  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 123
  • Joined: 07-May 08

Re: how to add Dispose to Class library?

Posted 25 January 2009 - 01:51 PM

thanks
Was This Post Helpful? 0
  • +
  • -

#4 turtleC++  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 123
  • Joined: 07-May 08

Re: how to add Dispose to Class library?

Posted 25 January 2009 - 02:59 PM

I receive this error when try to follow the sample from
http://msdn.microsof...ftw(VS.80).aspx
http://msdn.microsof...y/fs2xkftw.aspx
error== 'TestLog' does not implement interface member 'System.IDisposable.Dispose()'


namespace TestLogFile
{
	public class TestLog:IDisposable
	{
		private FileStream fStream;
		private string filePath;

		private bool isDisposed;


		//----------------------------------------------------------------
		//Function Name:  Constructor
		public TestLog(string path)
		{
			filePath = path;

			//Delete file if it exists.
			if (File.Exists(filePath))
			{
				File.Delete(filePath);
			}

			//Create new test log file.
			fStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.ReadWrite);
			fStream.Close();

			isDisposed = false;
		}



		//----------------------------------------------------------------
		//Function Name: Free
		//Purpose:  Call Dispose to free resources explicitly
		//http://msdn.microsoft.com/en-us/library/fs2xkftw(VS.80).aspx
		//http://msdn.microsoft.com/en-us/library/fs2xkftw.aspx
		public void Free()
		{
			//Pass true in dispose method to clean managed resources 
			//too and say GC to skip finalize 
			Dispose(true);

			//If dispose is called already then say GC to 
			//skip finalize on this instance.
			GC.SuppressFinalize(this);
		}




		//----------------------------------------------------------------
		//Function Name: ~TestLog
		//
		~TestLog()
		{
			//Pass false as param because no need to free managed resources 
			//when you call finalize it will be done by GC itself as its 
			//work of finalize to manage managed resources.
			 Dispose(false);
		}



		
		//----------------------------------------------------------------
		//Function Name: Dispose
		//Purpose:  dispose to free resources
		//
		protected virtual void Dispose(bool disposeStatus)
		{
			if (!isDisposed)
			{
				isDisposed = true;

				//Released unmanaged resources
				if (disposeStatus)
				{
					//Release managed resources
				}
			}
		}


	}
}




thanks
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6056
  • View blog
  • Posts: 23,493
  • Joined: 23-August 08

Re: how to add Dispose to Class library?

Posted 25 January 2009 - 03:06 PM

You need to implement the Dispose() with no arguments.
Was This Post Helpful? 0
  • +
  • -

#6 turtleC++  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 123
  • Joined: 07-May 08

Re: how to add Dispose to Class library?

Posted 25 January 2009 - 03:09 PM

Yes you are right, thanks. I changed the function name Dispose to Free which I shouldn't do it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1