Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8181441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:31:23+00:00 2026-06-07T00:31:23+00:00

I have a class which is in charge for error handling. I would like

  • 0

I have a class which is in charge for error handling. I would like to execute a process, if the destructor is called. But sadly the process would not start. The new processes call an exe with some arguments, which should send an email.
Why does this not work?

~ErrorH()
{
    if ((int)e > 0)
        SendErrorMail();
}

private void SendErrorMail()
{
    if (File.Exists("C:\\Program Files (x86)\\MailSend\\MailSend.exe"))
    {
        ProcessStartInfo mailsend = new ProcessStartInfo();
        mailsend.FileName = "C:\\Program Files (x86)\\MailSend\\MailSend.exe";
        mailsend.Arguments = "…";
        Process.Start(mailsend);
    }
}

If I execute the SendErrorMail function for example in the constructor, everything works fine. If I look at the debugger it seems like I reach the Process.Start(mailsend); command.
What went wrong? How could I fix this?

Edit

Ok now I have used the IDisposable method. It works fine, but does is use it correctly?

class ErrorH : IDisposable
{
private bool disposed = false;
...
public void Dispose()
{
    Dispose(true);
    GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool desposing)
{
    if(!this.disposed)
        if ((int)e > 0)
            SendErrorMail();
    disposed = true;
}

In Program I use:

using (Parameter p = new Parameter(args[0]))
{
...
}

The class ErrorH inheritance from Parameter.

Greetz

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:31:26+00:00Added an answer on June 7, 2026 at 12:31 am

    Rather than using destructors, which cannot be guaranteed to be called at current time, use interface System.IDisposable.

    Usually, it is a bad practice to use destructors in C# like C++, for example. Since we cannot determine the specific time the objects will be destroyed by Garbage Collector (GC), C# provides IDisposable which has a single method Dispose, that you can call it either explicitly when you finish using the object, or implicitly by using block.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started to write a class which would act much like the std::vector but
I have class Employee which is something like this. class Emp { int EmpID;
I have a class, which has 8 props / 8 columns in DB. But
I have serialized a class which used to be in namespace Temp, but now
I have class LegacyClass which inherits OldBaseClass. I'm considering a change to introduce a
I have class which have one public method Start , one private method and
I have class Money which is an @Embeddable @Embeddable public class Money implements Serializable,
I have class A which extends the Activity class. This class is in package
I have class World which manages creation of object... After creation it calls afterCreation
I have a class which represents exam,it can start/reset/pause exam, so the methods look

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.