Author Topic: Deleting temporary files at control disposal  (Read 2072 times)

0 Members and 1 Guest are viewing this topic.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Deleting temporary files at control disposal
« on: October 04, 2010, 05:21:42 PM »
I have not quite figured this out, and I am sure there is a solution that I have not found .. that seems to be the case ..

I've built a usercontrol and embedded about half a dozen files required for control to operate as expected. When the control is loaded, the needed resources are extracted to the users temporary folder, modified, loaded etc ...

When the application housing the usercontrol ends, presumably it calls the Dispose method of the control, which is where I located the IO.File.Delete(tempfile) call ... but the temp file isn't being deleted, in fact the Dispose method is never called .. at least I can't tell that it has been called.

If these files were in the main application, I would simply delete the files when the form is closing ... I'll be using this control in other applications in the future and I would like it to clean up after itself.

Any suggestions?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Deleting temporary files at control disposal
« Reply #1 on: October 04, 2010, 07:19:05 PM »
Code: [Select]
public partial class UserControl1 : UserControl, IDisposable // Implement Idisposable to force
    {     
        public UserControl1()
        {
            InitializeComponent();
        }
        //Destructor code to run when object is disposed
        ~UserControl1()
        {

        }

        //using blah // Will automatically call Dispose method for objects who class that implements IDisposable
        //{
   
        //}

        #region IDisposable Members

        public void Dispose()
        {
             GC.SuppressFinalize(this);
        }

        #endregion
    }



Code: [Select]
  [CommandMethod("Disposeee")]
        public static void Disposeee()
        {
            System.Windows.Forms.UserControl uc = new System.Windows.Forms.UserControl();
            if (uc != null)
            {
                uc.Dispose();
            }

        }

******EDITED*************


« Last Edit: October 04, 2010, 07:28:55 PM by Jeff H »

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Deleting temporary files at control disposal
« Reply #2 on: October 05, 2010, 12:42:58 AM »
Got it, works like a champ

I wish everything was as simple as this ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie