Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 273 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VB.NET Create temp file marked for removal

#1
Note that the code presented will work in versions of Visual Studio prior to VS2008 but will need to be altered as there are things like language extensions used in the code below which were new to Visual Studio as of VS2008 but the underlying code can and does work with VS2005, not sure about VS2003.

I have attached a demo VS2008 project.

There are times when developers need a temporary file created to do some work during the execution of a task followed by removing the file once the task has been completed. If the program crashes before you clean code (code to remove the temp file) runs to remove the file then it will be left behind. I know several developers this has happened to and ended up having to write code to get these files and remove them. The code presented below demonstrates how to mark a temporary file as remove when the application closes or you close the FileStream (wrapped in a language extension), which created the file. For precautions, it might be worth giving the file created by the FileStream a unique name so in the code the file name a random name using a language extension.

Create a button on a form called cmdCreateAndRemoveTempFileOnClose and place the following code into the click event

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


Create a code module and place the following into it

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


In the form you placed the first button add another button and call it cmdCreateAndRemoveTempFileOnClose2 with the code below for the click event

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


The second button code above removes the temp file when the FileStream is closed

Add another code module for my My Namespace addition for a message box wrapper for asking users a question (I have many more but this is all that is needed for the demo).

File contents

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


Reply

#2
Awesome stuff keep it up. :smile: I need something like this in my ImageViewer.
Reply

#3
Quote:(01-02-2011, 08:06 AM)Coder Wrote:

[To see links please register here]

Awesome stuff keep it up. :smile: I need something like this in my ImageViewer.

Speaking of image viewers, here is a language extension

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


Sample usage

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

Reply

#4
Nah, same problem with releasing HDC. If I don't the Billenear filter keeps hogging up memory, 800MB+
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through