Click here to Skip to main content
15,886,689 members
Home / Discussions / C#
   

C#

 
AnswerRe: Monitor FTP and SFTP folders through FileSystemWatcher class Pin
Garth J Lancaster2-Jun-16 21:52
professionalGarth J Lancaster2-Jun-16 21:52 
GeneralRe: Monitor FTP and SFTP folders through FileSystemWatcher class Pin
amjegan2-Jun-16 22:08
amjegan2-Jun-16 22:08 
GeneralRe: Monitor FTP and SFTP folders through FileSystemWatcher class Pin
Garth J Lancaster2-Jun-16 22:38
professionalGarth J Lancaster2-Jun-16 22:38 
AnswerRe: Monitor FTP and SFTP folders through FileSystemWatcher class Pin
Eddy Vluggen2-Jun-16 23:58
professionalEddy Vluggen2-Jun-16 23:58 
QuestionThe class MediaPlayer of namespace System.Windows.Media can't play music on OS Windows XP Pin
Member 111473382-Jun-16 19:49
Member 111473382-Jun-16 19:49 
AnswerRe: The class MediaPlayer of namespace System.Windows.Media can't play music on OS Windows XP Pin
OriginalGriff2-Jun-16 20:03
mveOriginalGriff2-Jun-16 20:03 
GeneralRe: The class MediaPlayer of namespace System.Windows.Media can't play music on OS Windows XP Pin
Member 111473382-Jun-16 20:16
Member 111473382-Jun-16 20:16 
QuestionSmall question on Finalizers Pin
Foothill2-Jun-16 8:56
professionalFoothill2-Jun-16 8:56 
Can I use finalizers as a backup for when IDisposable objects are not properly disposed?

I'll use a class that contains a thread as an example
C#
public sealed class TaskExecuter : IDisposable
{
  private Thread _thread;
  //... other class members such as Actions and WaitHandles
  //... all the other things that this class does

  // last ditch effort to ensure resources are cleaned up
  ~TaskExecuter()
  {
    if (_thread != null && _thread.ThreadState != ThreadState.Stopped)
    {
      //... if not null, dispose of managed system objects.
      _thread.Join();
    }
  }

  private void Dispose(bool disposing)
  {
    if (disposing)
    {
      //... release other system objects such as wait handles
      _thread.Join(1000);
    }
  }

  public void Dispose()
  {
    Dispose(true);
    GC.SupressFinalize(this);
  }
}

So in this case, the class has a thread that it can reuse through the lifespan of the class. What I am concerned with is what if I or another developer creates this class, uses it, and forgets to dispose of it. This would leave the thread in an uncontrollable state and not to mention certain other system objects until the program is terminated.

Can I prevent this by making other checks in a finalizer?
if (Object.DividedByZero == true) { Universe.Implode(); }
Meus ratio ex fortis machina. Simplicitatis de formae ac munus. -Foothill, 2016

AnswerRe: Small question on Finalizers Pin
Dave Kreskowiak2-Jun-16 9:07
mveDave Kreskowiak2-Jun-16 9:07 
GeneralRe: Small question on Finalizers Pin
Foothill2-Jun-16 9:55
professionalFoothill2-Jun-16 9:55 
GeneralRe: Small question on Finalizers Pin
Dave Kreskowiak2-Jun-16 10:53
mveDave Kreskowiak2-Jun-16 10:53 
GeneralRe: Small question on Finalizers Pin
Foothill2-Jun-16 11:22
professionalFoothill2-Jun-16 11:22 
GeneralRe: Small question on Finalizers Pin
Dave Kreskowiak2-Jun-16 11:58
mveDave Kreskowiak2-Jun-16 11:58 
GeneralRe: Small question on Finalizers Pin
Foothill3-Jun-16 5:10
professionalFoothill3-Jun-16 5:10 
AnswerRe: Small question on Finalizers Pin
Richard Deeming2-Jun-16 9:34
mveRichard Deeming2-Jun-16 9:34 
GeneralRe: Small question on Finalizers Pin
Foothill2-Jun-16 11:02
professionalFoothill2-Jun-16 11:02 
QuestionHow to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
somagunasekaran2-Jun-16 1:35
somagunasekaran2-Jun-16 1:35 
AnswerRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
Richard Deeming2-Jun-16 2:11
mveRichard Deeming2-Jun-16 2:11 
AnswerRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
OriginalGriff2-Jun-16 4:08
mveOriginalGriff2-Jun-16 4:08 
GeneralRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
Richard MacCutchan2-Jun-16 4:35
mveRichard MacCutchan2-Jun-16 4:35 
GeneralRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
OriginalGriff2-Jun-16 4:57
mveOriginalGriff2-Jun-16 4:57 
GeneralRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
Pete O'Hanlon2-Jun-16 5:37
mvePete O'Hanlon2-Jun-16 5:37 
GeneralRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
OriginalGriff2-Jun-16 6:05
mveOriginalGriff2-Jun-16 6:05 
GeneralRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
Mycroft Holmes2-Jun-16 13:03
professionalMycroft Holmes2-Jun-16 13:03 
AnswerRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
Gerry Schmitz2-Jun-16 4:58
mveGerry Schmitz2-Jun-16 4:58 

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.