Click here to Skip to main content
15,893,161 members
Home / Discussions / C#
   

C#

 
AnswerRe: Problem with AForge Neuro RunEpoch Pin
Pete O'Hanlon3-Jun-16 20:47
mvePete O'Hanlon3-Jun-16 20:47 
AnswerRe: Problem with AForge Neuro RunEpoch Pin
BillWoodruff4-Jun-16 7:36
professionalBillWoodruff4-Jun-16 7:36 
Questionmake BeginInvoke from a form that is invisble Pin
Member 125150673-Jun-16 8:46
Member 125150673-Jun-16 8:46 
AnswerRe: make BeginInvoke from a form that is invisble Pin
Dave Kreskowiak3-Jun-16 12:11
mveDave Kreskowiak3-Jun-16 12:11 
QuestionTrouble downloading results of http request Pin
Member 101734793-Jun-16 6:12
Member 101734793-Jun-16 6:12 
QuestionCannot Get Any Values From A WCF REST Service Pin
MadDashCoder3-Jun-16 5:56
MadDashCoder3-Jun-16 5:56 
AnswerRe: Cannot Get Any Values From A WCF REST Service Pin
Gerry Schmitz3-Jun-16 8:28
mveGerry Schmitz3-Jun-16 8:28 
GeneralRe: Cannot Get Any Values From A WCF REST Service Pin
MadDashCoder3-Jun-16 13:32
MadDashCoder3-Jun-16 13:32 
GeneralRe: Cannot Get Any Values From A WCF REST Service Pin
Gerry Schmitz3-Jun-16 19:15
mveGerry Schmitz3-Jun-16 19:15 
QuestionMonitor FTP and SFTP folders through FileSystemWatcher class Pin
amjegan2-Jun-16 21:05
amjegan2-Jun-16 21:05 
QuestionRe: Monitor FTP and SFTP folders through FileSystemWatcher class Pin
Richard MacCutchan2-Jun-16 21:41
mveRichard MacCutchan2-Jun-16 21:41 
AnswerRe: Monitor FTP and SFTP folders through FileSystemWatcher class Pin
amjegan2-Jun-16 21:55
amjegan2-Jun-16 21:55 
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 

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.