Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We don't know the details of your code but the fact that your class library needs to be aware of when the process is exiting might indicate a design flaw of your application.</p> <p>If you need to release resources or clean up other things in a deterministic way you should have a look at the <code>IDisposable</code> interface. If the classes exposed by your library implement this interface caller can state easily that they no longer need the dll functionality by calling <code>Dispose()</code>. </p> <p>Maybe a good starting point for further reading are the following articles:</p> <blockquote> <ul> <li><p><strong><a href="http://msdn.microsoft.com/en-us/library/fs2xkftw.aspx" rel="nofollow noreferrer">MSDN: Implementing a Dispose Method</a></strong></p></li> <li><p><strong><a href="http://www.codeproject.com/KB/dotnet/idisposable.aspx" rel="nofollow noreferrer">IDisposable: What Your Mother Never Told You About Resource Deallocation</a></strong></p></li> </ul> </blockquote> <p>For example you could have the following class in your class library:</p> <pre><code>using System; using System.IO; public class ResourceManager : IDisposable { private Stream _resource; private bool _disposed; public void Dispose() { Dispose(true); // Use SupressFinalize in case a subclass // of this type implements a finalizer. GC.SuppressFinalize(this); } public void Dispose(bool disposing) { if (!_disposed) { if (disposing) { Console.WriteLine("Exiting Process. Cleaning up."); // free resources here if (_resource != null) _resource.Dispose(); Console.WriteLine("Object disposed."); } // Indicate that the instance has been disposed. _resource = null; _disposed = true; } } } </code></pre> <p>In your main module you can then use in the following way; the <code>using</code> statement will guarantee that the <code>Dispose()</code> method is called:</p> <pre><code>using System; using System.Windows.Forms; static class Program { /// &lt;summary&gt; /// The main entry point for the application. /// &lt;/summary&gt; [STAThread] static void Main() { using (ResourceManager manager = new ResourceManager()) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload