[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Adventures with "OleControl Shell.Explorer.2" deleting the temporary files issue.

Posted on 2012-12-28
5
Medium Priority
?
1,009 Views
Last Modified: 2013-01-02
ok, got my OleControl Shell.Explorer.2 activex control to work and it shows pdfs and graphics files.  But of course it needs a pdf file to exist so I create one.  I am storing the documents in my mssql database as a varchar(max)

So, when my user wants to view the document, I create a temporary file and ole.navigate2 to the file.  

But when I close the form, I want to delete the temporary file but of course it is in use.

So I navigate2 to "About:Blank" but I still have to wait .3 of a second before it is released.

inkey(.3)
delete file (tempfilename)

Open in new window


Tried a DOEVENTS but no difference.  I also have this after I navigate to the blank page:

DO WHILE (this.Olecontrol1.Busy OR this.Olecontrol1.ReadyState <> 4) 
   DOEVENTS
ENDDO

Open in new window


but again, still need the delay.  So any ideas, not sure if the inkey(.3) is going to be enough for all my client's slow machines and it seems like a patch and not a solution.
0
Comment
Question by:peterhupp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 43

Assisted Solution

by:pcelba
pcelba earned 2000 total points
ID: 38728412
Yes, the control (or OS) releases the file for deletion after certain delay obviously. I am also navigating to a blank page and waiting for ready state and that's not sufficient in some cases...

So I am attempting to delete the temp file in a loop for 2 seconds:
ldDate = DATE()
lnTime = SECONDS()
llSuccess = .F.
DO WHILE !m.llSuccess AND SECONDS() < m.lnTime + 2 AND DATE() = m.ldDate
TRY
  DELETE FILE ...
  llSuccess = .T.
CATCH
ENDTRY
DOEVENTS FORCE
ENDDO

The advantage of this solution is no delay when the deletion attempt succeeds.
But it still does not ensure the file deletion sometimes. In such case the file waits for temp folder general cleanup which deletes all files older than 1 week from the temp folder when the app exits.
0
 
LVL 3

Accepted Solution

by:
peterhupp earned 0 total points
ID: 38728426
Actually I figured this one out and I think it is the best solution.  By using the open I do not attempt the deletion till it either times out or I am able to get RW access.

   lnAttempts= 0
   lnHandle = -1
   DO WHILE lnHandle=-1 and lnAttempts<51 
      lnAttempts = lnAttempts + 1 
      lnHandle = fopen(this.tmpFileName,12)  
      INKEY(.1)
   enddo
   FCLOSE(lnHandle)
   * if timeout handle that otherwise
   DELETE file (this.tmpFileName)

Open in new window


This is a subset of my code but it shows the logic of the fopen to test the release of the file.
0
 
LVL 43

Expert Comment

by:pcelba
ID: 38728441
Yes, your solution must work because the delay could be more than 5 seconds which is enough even for slow systems.
0
 
LVL 3

Author Comment

by:peterhupp
ID: 38728454
I did try the try..delete file.... catch but sometimes it would make VFP crash.
0
 
LVL 3

Author Closing Comment

by:peterhupp
ID: 38736052
My solution worked the best and 100% of the time.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question