Problem cleaning up temporary files.

This isn't MFC specific so I apologize.  I just like the information 
provided by the regular members of this group.

I have an application that has a Rich Edit control.  Next to the Rich Edit 
control is a Print button.
To avoid all the details of printing, I decided to save the contents of the 
control to a RTF file, then do ShellExecuteEx("blahblah.rtf", "print", ...).

This works fine.  But, I sure would like to remove these temporary files. 
But I am finding that to be a tricky problem to solve.  At first, I thought 
I would wait for the process started to end.  But, in the case of DDE, there 
is no process to wait on, so I will either delete the file immediately or 
not at all, depending on how I write the code.  This is a problem because I 
might actually delete the file before the other process has a chance to 
load/print it.

It appears to me that in a scenario like this, there really is no way to 
clean up the temporary files in all situations.  You can on most (a valid 
process handle is returned and you wait on that handle to terminate, then 
remove the file).  And, I guess I could live with that, but it sure doesn't 
guarantee that the users system won't start collected temporary files.

Thoughts?
Leo V. 


0
11/16/2006 1:02:07 AM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
318 Views

Similar Articles

[PageSpeed] 6


Leo V. wrote:

> 
> It appears to me that in a scenario like this, there really is no way to 
> clean up the temporary files in all situations.  You can on most (a valid 
> process handle is returned and you wait on that handle to terminate, then 
> remove the file).  And, I guess I could live with that, but it sure doesn't 
> guarantee that the users system won't start collected temporary files.

At the least, you could use the user's temp directory. I believe it gets 
emptied when they clean. But you might check... And there is the windows 
temp. I use the user's for patches.

http://msdn2.microsoft.com/en-us/library/ms649274.aspx
CSIDL_INTERNET_CACHE

Best, Dan.

0
public21 (290)
11/16/2006 1:39:31 AM
Thanks Dan.  I do use the temporary users directory under Documents and 
Settings...

"Dan Bloomquist" <public21@lakeweb.com> wrote in message 
news:njP6h.5641$ya1.3634@news02.roc.ny...
>
>
> Leo V. wrote:
>
>>
>> It appears to me that in a scenario like this, there really is no way to 
>> clean up the temporary files in all situations.  You can on most (a valid 
>> process handle is returned and you wait on that handle to terminate, then 
>> remove the file).  And, I guess I could live with that, but it sure 
>> doesn't guarantee that the users system won't start collected temporary 
>> files.
>
> At the least, you could use the user's temp directory. I believe it gets 
> emptied when they clean. But you might check... And there is the windows 
> temp. I use the user's for patches.
>
> http://msdn2.microsoft.com/en-us/library/ms649274.aspx
> CSIDL_INTERNET_CACHE
>
> Best, Dan.
> 


0
11/16/2006 2:13:35 AM
There are a few things that come to mind:

1. You could clean up the files when you restart the program at a later 
time.
2. You can write the files to a temp folder (I think you said you're doing 
that).
3. You could use a timer.  My guess is the file doesn't need to be around 
after it is sent to the spooler so after a certain amount of time you could 
delete the temp file.
4. You could have a "clean-up" function that you allow the user to call from 
time to time, perhaps from a menu entry.
5. You could, as you say, save the process handle and get notified when the 
process exits and do any cleanup at that point.  This would only work well 
if you do one file at a time.

I would probably keep a list of the temp files I created and then clean them 
up when the application exits.  To be even more clever I might keep a list 
of instance handles and check then when the program is exiting and warn the 
user that they may be exiting too soon.  You see this kind of thing in 
programs like Outlook where it warns you if it's in the middle of sending a 
file (something being done on a different thread) if you try to exit.

Tom

"Leo V." <lviolette.SpamMeNot@orrtax.com> wrote in message 
news:%23jNsfrRCHHA.1300@TK2MSFTNGP03.phx.gbl...
> This isn't MFC specific so I apologize.  I just like the information 
> provided by the regular members of this group.
>
> I have an application that has a Rich Edit control.  Next to the Rich Edit 
> control is a Print button.
> To avoid all the details of printing, I decided to save the contents of 
> the control to a RTF file, then do ShellExecuteEx("blahblah.rtf", "print", 
> ...).
>
> This works fine.  But, I sure would like to remove these temporary files. 
> But I am finding that to be a tricky problem to solve.  At first, I 
> thought I would wait for the process started to end.  But, in the case of 
> DDE, there is no process to wait on, so I will either delete the file 
> immediately or not at all, depending on how I write the code.  This is a 
> problem because I might actually delete the file before the other process 
> has a chance to load/print it.
>
> It appears to me that in a scenario like this, there really is no way to 
> clean up the temporary files in all situations.  You can on most (a valid 
> process handle is returned and you wait on that handle to terminate, then 
> remove the file).  And, I guess I could live with that, but it sure 
> doesn't guarantee that the users system won't start collected temporary 
> files.
>
> Thoughts?
> Leo V.
> 


0
tserface (3861)
11/16/2006 3:56:50 AM
Reply:

Similar Artilces:

file will not save
One of my excel files will not save. it seems to work ok, but when i try to save it, i get a "document not saved" message. the file cannot be closed unless i agree not to try to save it. any ideas why i cannot save this file? #1. Are you working off a floppy? If yes, then don't do this. Use windows explorer to copy from floppy to harddrive and work from there (and save there). Then use windows explorer to copy back to floppy. #2. You're saving to a location that you don't have permission to save to. #3. Your diskdrive is out of space??? missionary wrote...

Missing File Day 3 No resolution ?
No. Is this file something that can be sent to me? -----Original Message----- From: "Diane Poremsky" <info@cdolive.com> Sent: 4/12/2004 8:15:04 PM Subject: Re: Missing file still.... did you have different versions or suites of office installed? -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Coauthor, OneNote 2003 for Windows (Visual QuickStart Guide) Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com "Kyle" <anonymous@discussions.microsoft.com> wrote in mess...

Problems with OALGen after Raid Upgrade
Hello, We have recently upgraded the raid array on our windows 2003 SBS server, and we've been stomping out bugs since. I've almost got them all fixed except for a few that deal with exchange offline address book. Here are the errors from the logs Event ID: 9126 OALGen encountered error 80004005 while calculating the offline address list for address list '\Global Address List'. This offline address list will not be available for client download. - /o=AALBERSTOOL/cn=addrlists/cn=oabs/cn=Default Offline Address List For more information, click http://www.microsoft.com/cont...

date problem #10
Thanks a lot, Dave This piece of code works great. M P Redd -- mpredd ----------------------------------------------------------------------- mpreddy's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1327 View this thread: http://www.excelforum.com/showthread.php?threadid=26358 ...

Problem
Ever since I added a Microsoft Exchange Server Account and all it6s associated folders and its in-box to my pre-existing Personal Outlook 2003 POP3 folders, I have had nothing but confusion. The Exchange Server account from my workplace downloads its messages into the in-Box for my private ISP POP3 account and vice versa. When I try to configure a rule for my personal POP3 account so that any messages addressed to my workplace account are loaded into the exchange server in-box on my client PC, the software tells me I have to go on-line to Exchange Server - even to create rules for th...

Problem changing parent Business unit
WE have re-arranged some business units into a more appropriate hierarchy, however, we have noticed that a user in a role with deep privileges (own business unit and children I think) to read users can only see users in his own business unit and only one of the child business units (there are 2 child business units). We cannot enable him to see all the users in both child business units. We tried reassigning the parent business unit to the one child that is not appearing, but it doesn't seem to make any difference. WE also tried adjusting the privileges up and down (i.e. Global and local...

create new users STRANGE problem
Hi, I'm developing a web application (using standard asp and not asp.net) to let certain remote users administer exchange 2003. I have installed win2003 standard edition, exchange 2003 enterprise edition,owa and my web application on the same server. My web app, let users to create mailboxes, delete mailboxes, change user password. All works fine, but for example, if I reboot the server, a web application user can create 50 mailboxes. But when any of these users log on to owa, something goes wrong and the admin user cannot mailbox enable other user accounts through the web app, even if he ...

Problem w/ Outlook
I'm running Office XP and all of a sudden I can't move messages to other folders not delete messages from my Inbox. It doesn't give me a specific error code, just suggests that I restart Outlook. I've tried that with no success. I went to ControlPanel and repaired my Office installation. Any ideas? Eudora is looking beter all the time. ...

ProbleM: when I restore a mailbox using Exmerge with a pst file, nothing is transferred.
Hi, I am practising Exmerge for a big remote site migration in a couple of weeks. One thing I dont understand is that I can backup one test mailbox fine using Exmerge (I know this works, as I have opened the mailbox pst file within outlook and everything is there), but when I perform the restore using the pst file, nothing happens. There is no error messages, and Emerge goes through the motions (though it finishes supsiciously quick), but when I open the mailbox, no emails have been restored. Although it is great that Exmerge is working for the backup part of the stage, I am disappointed it i...

Problems with Outlook 2003
This only happens with externally sent messages. Internal messages work fine. One of my users alerted me to this issue, so I tested this myself. I created 2 messages (internal and external) and added delayed delivery to both. They were both set to go out at the same time. The internal message went, and the external message is still in the outbox. The user who alerted me to this found her message went "before" the scheduled time.We are not running in cached mode and of course running Outlook on Exchange. Is this a bug? ...

Importing ofx file
I'm using Money 2004 Premium and I was downloading my bank account information in ofx format directly in Money; recently this stopped working and I have to manually import the file into money. Not a big deal, but an annoyance just the same. Does anyone have a suggestion as to a fix for this? tia dennisd In message <QK3kl.3776$rt3.617@newsfe15.iad>, dennis <djd@home.net> writes >I'm using Money 2004 Premium and I was downloading my bank account >information in ofx format directly in Money; recently this stopped working >and I have to manually import the fi...

memory problem of Excel 2003 copy & paste
Hi all, I am using Excel 2003 for some project. I am having 2GB C drive harddisk space. After a while, the Excel begins to be extremely slow in copy and paste... It takes about half an hour to copy and paste just a few cells... I've consulted people. It seems a memory problem. But I cannot close my windows and kill the processes, because I am running long-running (overnight) jobs... I cannot reboot either. Is there a way to clean the memory and let Excel 2003 clipboard function properly without rebooting or killing my 4 long-running processes? Thanks! p.s. I am sure this is an is...

error when opening .accdb file
I don't think this is a new issue but I can't seem to find the resolution... I get an error when opening my Access 2007 formatted database stating that the file could not be found, though at the same time the file opens successfully. -- Error is intermittent. On occasions where the error does not occur, the file opens normally (I have never had an occasion where the file did not open at all) -- I have only seen the error happen when I have a 'Display Form' set in the Application Options for the 'Current Database' -- The database contains macros, VBA m...

Using namespaces? I've some messy nested contexts that I want to clean up...
Hi, I've got the following code structure Class A { ... private: Class B { public: enum C { ENUM X } C MyVar; C MyFunc() } } So for function definitions in B I have to write A::B::C A::B::MyFunc() and for objects of B in A if(pb->MyVar==B::ENUM_X) It's all just a bit messy. Isn't it. Someone please help. Regards. ...

Windows XP Shared PC
We are using Outlook 2000. The PC, which already had Microsoft Office 2000 loaded on it, was upgraded from Win 98 to Win XP. I then created Windows XP logons for all four people that will be sharing this PC. When I did, the Outlook shortcut automatically ended up on the desktop of each person when they individually logged in. When I clicked the shortcut the first time I went in to each person's desktop, I setup the mail account for JUST THAT PERSON. And when I go back and log into each person's desktop it still shows ONLY THEIR ACCOUNT. However, whatever mail they receive ALS...

Public Folder/OWA problem
We're running a pure Ex2k3 environment. I'm trying to setup a public folder where end-user software can be posted. This way, users can access our front-end OWA server outside of the network, open public folders, and then save the software to their local PC. The problem is that i get a "403 Forbidden" error whenever i try to download the file off of OWA. I checked that users had all permissions to the folder.. I found this TechNet article that describes something very similar (http://support.microsoft.com/kb/834743/en-us). The only problem is that it refers to som...

Shared workbook and VBA problem
Shared workbook and VBA problem Hi Group, I am new at this Excel stuff and I am hitting my head on a silly problem that I am sure many have seen before. I wrote a very simple spreadsheet where I use the Calendar control to pick some dates. Everything was fine until I decided that I needed to share it on the network with other users. As soon as I share it the calendar control stops working. I get a "runtime error 1004, unable to set left property of oleobject class". That's because the first thing I try to do is position the calendar. If I don't do that, it still doesn't...

outlook express 6 password problem
Help I have outlook express 6, windows xp. My internet provider just changed from att broadband to comcast. now i keep getting a password rejected error and i cant receive any mail. i cant seem to find a way to shut off the password. in my wifes page of xp it works ok. Hi, Bill - This is a group to support Outlook from the Office group of programs. Outlook Express is a part of Internet Explorer and is a quite different program, despite its similar name.. You will probably get a faster and more expert answer if you post this to an Outlook Express news group. Try posting in one of these n...

Default Folder for PST files?
I have a slightly different question relating to the above: I already have my current & archive pst files stored in my own personal folders. When I want to open my archive folder I right-click Outlook Today & select 'Open Outlook Data File'. Everytime, Outlook defaults to its own path (Documents & Settings\User\Local Settings\Application Data\Microsoft\Outlook\) This is really annoying & I would like it to default to opening a customised path, such as C:\Mail\ Any suggestions? -- Cheers, James Goodman Hi James, if you want to displace your pst file, please ...

Problems Recieving Emails
I have two accounts one for me and one for the better half. I have them set up on outlook correctly . The problem is I can only down load the wife's email using out look express. I also use Mail Washer to wash the crud out and it does not see the email either although it logs on to the accounts. Cox is my ISP. I have discussed it with them and the answer was to take it up with Microsoft, but that was a waste of time as they have not found any cause for the action. Any ideas of the problem would be kindly accepted. 1. Version of Outlook? 2. Separate mail profiles? 3. Separate Windows L...

Importing Contract from .csv file is not working
Hi, I m new to CRM. I have two column in my .CSV file. name and phone number i am trying to imort them to CRM contact Module. Everything happen smooth, i mean mapping of fields. But it does not Import the Contact in to CRM , instead the task goes and sits into the Buld Import Activity. And shows the Status as "Pending". I am using CRM Client and all the services are running..... Please let me know what could be the problem.. Labhesh Shrimali Bangalore - India MCP. Hi you have to change the Log on account for the Workflow Service on the CRM Server Regards, Dirk F ...

Hebrew Oulook problem solved
Removing the com add-in Outlook Attachment remover solved the problem. ...

Crystal Reports problem 07-11-05
Hi, Client was seeing the usual logon problem when trying to access reports. Tried re-starting all services and this error disappeared but now isn't showing any reports at all. Checked all the files and databases and can't see where the problem is - any suggestions please. By the way this is post install - no one has yet been prompted to install the activex viewer. Hello Pete, This could be Active Directory related. Could you check you added the Microsoft CRM server and the SQLServer computer to the Pre-Winodws 2000 Compatible Access group? This solved a number of problems at ...

Date Problem #2
Hi All Please can someone advise me what to do, I have a date in a textbox where I am using the AddDate method to increment the day , but I am getting strange results. Is this because the US date? if so how do I change this to work for the UK date? Any help would be greatly appreciated regards Subs Hiya- i'm not sure what formula you're using- I put a random date in A1 and pasted the following formula in B1 & C1: =DATE(YEAR(A1),MONTH(A1),DAY(A1)+1) it increased the day by 1 in both cells. I then changed the format to UK and it worked just fine. Is this what you're l...

clip art preview problem
I just downloaded the new microsoft security pack and now my Clip Art function on all of my office programs will not display a preview from the Online Clip Art search program. I know it searches because lots of boxes come up and some of them will insert and show up in my document if I double click them. but I can't spend all of my time inserting them into my document to see if they are the ones I want. A few times the Office Assistant has said that a picture is not available because I do not have the right graphic converter and to press help for more info - that just takes me in ...