473,499 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[VB.net-WinAPP] - Slow Internet Cache

79 New Member
Hi,

Expand|Select|Wrap|Line Numbers
  1.     Public Sub FindInternetCache()
  2.         Dim cacheDir As String = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)
  3.  
  4.         Dim cacheFiles As ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles(cacheDir, FileIO.SearchOption.SearchAllSubDirectories, "*.*")
  5.  
  6.  
  7.         Dim fCounter As Integer = 0
  8.         Dim fSize As Double
  9.  
  10.  
  11.         For Each cacheFound As String In cacheFiles
  12.             fCounter = fCounter + 1
  13.  
  14.  
  15.         DisplayBox.Text &= Environment.NewLine
  16.         DisplayBox.Text &= "Found: " & cacheFound & Environment.NewLine
  17.  
  18.  
  19.             fSize += My.Computer.FileSystem.GetFileInfo(cacheFound).Length
  20.         Next
  21.  
  22.  
  23.         DisplayBox.Text &= Environment.NewLine
  24.         DisplayBox.Text &= "IE Temporary Internet Files Found " & "(" & fCounter & " Files) " & SetBytes(fSize) & Environment.NewLine
  25.  
  26.  
  27.     End Sub
  28.  
I am using the above function to Output all the files in the Temporary Internet Files folder - its working alright. But its very slow and also hangs.

I was wondering if theres a better method to do this.

Thank you
Regards
Sep 26 '08 #1
13 1761
Plater
7,872 Recognized Expert Expert
Is it faster if you use the the .NET Directory.GetFiles() function and not that strange Computer.FileSystem call?
Sep 26 '08 #2
zubair1
79 New Member
Is it faster if you use the the .NET Directory.GetFiles() function and not that strange Computer.FileSystem call?
it seems to be the same

i used it like this to find all files

Expand|Select|Wrap|Line Numbers
  1. Directory.GetFiles(cacheDir, "*.*", SearchOption.AllDirectories)
:(
Sep 26 '08 #3
Curtis Rutland
3,256 Recognized Expert Specialist
Try using the DirectoryInfo object. See if that is any faster.
Sep 26 '08 #4
zubair1
79 New Member
Try using the DirectoryInfo object. See if that is any faster.
Oops, sorry i forgot about this :(

I tried the directoryInfo object with no help.

:(
Sep 28 '08 #5
Plater
7,872 Recognized Expert Expert
Well the temporary internet cache is usually PACKED with files... I have over 3k in mine right now.
It takes IE quiet a long time to flush the cache as well.

Also, why are you doing this??
fCounter = fCounter + 1

Why not just say fCounter=cacheFiles.Length after the loop (or before it, it does not matter
Sep 29 '08 #6
zubair1
79 New Member
Well the temporary internet cache is usually PACKED with files... I have over 3k in mine right now.
It takes IE quiet a long time to flush the cache as well.

Also, why are you doing this??
fCounter = fCounter + 1

Why not just say fCounter=cacheFiles.Length after the loop (or before it, it does not matter
Hi,

it has alot of files but i've seen many apps made in VB and C# that shows all the cache files to the end user but works perfectly fine :(

yeah, i learned that very late about using .length =P

but i still use fCounter to determine how many files were deleted.
i also removed that thinking maybe it could be slowing down :( but that didn't help either :(

:(
Sep 29 '08 #7
Plater
7,872 Recognized Expert Expert
Well I just implented it and I can tell you that its the string concatination that is killing you. I re-wrote it to use a StringBuilder object instead of just concatinating text to the texbox.
Here is the last line (I am not pasting in the Found: lines since there is alot):
IE Temporary Internet Files Found (10492 Files) 203080648

It took .8 seconds. Now granted that time was recorded after the whole thing had been searched durring testing, so it was all indexed for faster searching, but it wasn't too much longer.

So consider making your function return a string value (from a stringbuilder) rather then working directly with a textbox.
Sep 29 '08 #8
zubair1
79 New Member
Well I just implented it and I can tell you that its the string concatination that is killing you. I re-wrote it to use a StringBuilder object instead of just concatinating text to the texbox.
Here is the last line (I am not pasting in the Found: lines since there is alot):
IE Temporary Internet Files Found (10492 Files) 203080648

It took .8 seconds. Now granted that time was recorded after the whole thing had been searched durring testing, so it was all indexed for faster searching, but it wasn't too much longer.

So consider making your function return a string value (from a stringbuilder) rather then working directly with a textbox.
Hi,

WoW - i was having a doubt that it might be something with the way of outputing the results but i'm still not sure how you did it :(

Is it possible for you to paste the code please =(

Would really appreciate that

Regards
Sep 29 '08 #9
Plater
7,872 Recognized Expert Expert
Well you are aware that string concatination is a degrading effect right? (I only recenlty learned just how BAD it gets)
Everytime you do a &= (or += in c#), it recreates the entire string. So as your string gets longer, it takes more and more time. With a StringBuilder, it does not re-create the string, it does what you would think the &= does, just append things to the end of the string.

I wrote my code in C#, but you could probably see what the changes where:
Expand|Select|Wrap|Line Numbers
  1. private string FindInternetCache()
  2. {
  3.     DateTime Start = DateTime.Now;//Only used for timing
  4.     StringBuilder retval = new StringBuilder("");
  5.     int fCounter = 0;
  6.     double fSize = 0.0;
  7.     string cacheDir = "";
  8.  
  9.     cacheDir= Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
  10.     DirectoryInfo di = new DirectoryInfo(cacheDir);
  11.     FileInfo[] cacheFiles=di.GetFiles("*.*", SearchOption.AllDirectories);
  12.  
  13.     foreach (FileInfo cacheFound in cacheFiles)
  14.     {
  15.         fCounter = fCounter + 1;
  16.         fSize += cacheFound.Length;
  17.         retval.AppendFormat("Found: {0}\r\n", cacheFound.FullName);
  18.     }
  19.     retval.AppendFormat("\r\nIE Temporary Internet Files Found ({0} Files) {1}\r\n", fCounter, fSize);
  20.     DateTime End = DateTime.Now;//Only used for timing
  21.     TimeSpan t = (End - Start);//Only used for timing
  22.  
  23.     return retval.ToString();
  24. }
  25.  
Sep 29 '08 #10
zubair1
79 New Member
Awesome,

Thanks for the code Platter :) looks great

and also thanks alot for letting me know about &= never knew it could be that bad :(

I tried using this method - the StringBuilder method but it isn't working :(

i get declare errors when trying to use StringBuilder command

Expand|Select|Wrap|Line Numbers
  1. StringBuilder retval = new StringBuilder("");
is the stringbuilder on for C#

how can i use this on VB.net (vb2005)

Thanks in advance
Sep 29 '08 #11
Curtis Rutland
3,256 Recognized Expert Specialist
The StringBuilder is in the System.Text namespace.

So, you could use
Expand|Select|Wrap|Line Numbers
  1. Imports System.Text
or you can declare it as
Expand|Select|Wrap|Line Numbers
  1. Dim retval As New System.Text.StringBuilder("")
Sep 29 '08 #12
zubair1
79 New Member
The StringBuilder is in the System.Text namespace.

So, you could use
Expand|Select|Wrap|Line Numbers
  1. Imports System.Text
or you can declare it as
Expand|Select|Wrap|Line Numbers
  1. Dim retval As New System.Text.StringBuilder("")
Too Good =D

Thanks it worked that way :)
Sep 29 '08 #13
zubair1
79 New Member
THANK YOU PLATTER :)

it worked :)

The method you showed worked :)

its working pretty fast now :)

Thanks for the marvelous help :) you're the best ;)
Sep 29 '08 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

9
3099
by: gulu man | last post by:
Hi, What is the substitute for COM objects in .NET? How can I create something similar to com in .net? Is it still possible? Thank you
20
3291
by: Olav.NET | last post by:
I am a .NET/C++ developer who is supposed to do some work with Access. I do not know much about it except for the DB part. Questions: *1* I am looking for INTENSIVE books to get quickly up to...
21
2810
by: TAM | last post by:
Hi, I read that ASP.NET uses VB.NET instead of VBScript. I also read that ASP.NET is a subset of VB.NET. So if I learn VB.NET first then do I have the knowledge for programming ASP.NET...
9
2741
by: Bob | last post by:
Is ASP.NET 1.1 available on the 64 bit extended version of Windows 2003 Server? When I install VS.NET 2003 I then get Service Unavailable from IIS when navigating to the main under construction...
132
4712
by: Kevin Spencer | last post by:
About 2 years ago, and as recently as perhaps 1 year ago, I can recall seeing many posts about what language to use with ASP.Net. The consensus was that employers paid more for C# programmers, and...
16
2123
by: Nathan Sokalski | last post by:
I have Visual Studio .NET and SQL Server Desktop Engine on my computer. I have created an empty database using Visual Studio .NET's Server Explorer. However, I am having trouble connecting to the...
2
1214
by: Juan T. Llibre | last post by:
Welcome to the ASP.NET FAQ. Thank you for reading this FAQ! Use it to improve your online experience. The Microsoft Public Newsgroups allow users of Microsoft products to exchange technical ...
0
1499
by: Juan T. Llibre | last post by:
Welcome to the ASP.NET FAQ. The online version of this FAQ is at http://asp.net.do/faq/ Thank you for reading this FAQ! Use it to improve your online experience. The Microsoft Public...
13
1592
by: Kenneth Windish | last post by:
Hi, I wrote a simple web application using web matrix. When I run it on my local computer all works fine, but when I run it on hosting site all hyperlinks are not working and just postback to...
13
1525
by: Steve H. | last post by:
Hi all, I'm searching for a few good books on asp.net and c#. I'm afraid of buying books here in denmark that i cant read though before i get them, becuase 90% of them are just pure junk. I...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3098
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.