473,663 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with a long running process?

I'm trying to make, what I thought, would be a simple application.
This application will help me organize files I have a lot of, on my
computer(ebooks , pictures, etc..). I'm currently dealing with over
25,000 files in a couple hundred directories.

I'm currently trying to collect the list using this

Try
For Each foundfile As String In
My.Computer.Fil eSystem.GetFile s(mySource,
FileIO.SearchOp tion.SearchAllS ubDirectories, "*.*")
Application.DoE vents()
listOfFiles.Add (foundfile)
Next
Catch ex As System.Unauthor izedAccessExcep tion
MessageBox.Show (ex.Message & vbNewLine & "Please choose another
source folder")
End Try

But with only the 25,000 files I currently have, I get the clr warning
message. I put the Application.DoE vents() in hoping to solve the
problem but it doesn't. So I stepped through the code and it is
hanging on the for each line.

I've been googling around and I think I can probably solve my problem
by using a backgroundworke r. But after reading some on the use of it
I'm simply lost. Heck, I'm not even sure I need to use the
backgroundworke r to solve the problem. But from what I've read it
should be able to solve the problem I'm having.

If there's simple way to do what I need could someone tell me about
it?

But also, could someone please give a full, short example, for a
novice to vb.net, to using a backgroundworke r to list all files using
for each basing the example on my code above? Something I can plug
into a new app and step through to gain some understanding of the
backgroundworke rs usage? From what I've read it seems like it could be
very very useful to know how to use it.

---
Kyote
Mar 19 '07 #1
6 1784
I'm not really sure what your problem is, you never say, other than "I get
the clr warning message". That's not specific enough to provide you with
some help.

This has an example of using the background worker.

http://msdn2.microsoft.com/en-us/lib...undworker.aspx

Robin S.
--------------------------------------
"Kyote" <ky********@nos pamhotmail.comw rote in message
news:6g******** *************** *********@4ax.c om...
I'm trying to make, what I thought, would be a simple application.
This application will help me organize files I have a lot of, on my
computer(ebooks , pictures, etc..). I'm currently dealing with over
25,000 files in a couple hundred directories.

I'm currently trying to collect the list using this

Try
For Each foundfile As String In
My.Computer.Fil eSystem.GetFile s(mySource,
FileIO.SearchOp tion.SearchAllS ubDirectories, "*.*")
Application.DoE vents()
listOfFiles.Add (foundfile)
Next
Catch ex As System.Unauthor izedAccessExcep tion
MessageBox.Show (ex.Message & vbNewLine & "Please choose another
source folder")
End Try

But with only the 25,000 files I currently have, I get the clr warning
message. I put the Application.DoE vents() in hoping to solve the
problem but it doesn't. So I stepped through the code and it is
hanging on the for each line.

I've been googling around and I think I can probably solve my problem
by using a backgroundworke r. But after reading some on the use of it
I'm simply lost. Heck, I'm not even sure I need to use the
backgroundworke r to solve the problem. But from what I've read it
should be able to solve the problem I'm having.

If there's simple way to do what I need could someone tell me about
it?

But also, could someone please give a full, short example, for a
novice to vb.net, to using a backgroundworke r to list all files using
for each basing the example on my code above? Something I can plug
into a new app and step through to gain some understanding of the
backgroundworke rs usage? From what I've read it seems like it could be
very very useful to know how to use it.

---
Kyote

Mar 19 '07 #2
Kyote wrote:
I'm trying to make, what I thought, would be a simple application.
Join the club... =)))
This application will help me organize files I have a lot of, on my
computer(ebooks , pictures, etc..). I'm currently dealing with over
25,000 files in a couple hundred directories.

I'm currently trying to collect the list using this

Try
For Each foundfile As String In
My.Computer.Fil eSystem.GetFile s(mySource,
FileIO.SearchOp tion.SearchAllS ubDirectories, "*.*")
Application.DoE vents()
listOfFiles.Add (foundfile)
Next
Catch ex As System.Unauthor izedAccessExcep tion
MessageBox.Show (ex.Message & vbNewLine & "Please choose another
source folder")
End Try

But with only the 25,000 files I currently have, I get the clr warning
message. I put the Application.DoE vents() in hoping to solve the
problem but it doesn't. So I stepped through the code and it is
hanging on the for each line.
<snip>

Before the loop enters its initial cicle, it will first have to grab
all the files from all sub folders off the base path you specified.
You can't put a DoEvents into this, cause it all will happen in the
GetFiles() instruction. Also, there's not much sense to put this in a
loop unless you want to do something with each file.

One possible way to execute what you want is just to assign the array
of file names directly to listOfFiles (which I assume is a List(Of
String)) or return it as an array.

Nevertheless, if you want to have some control over the loop, you may
consider loading the files folder by folder:

<aircode>
Sub LoadFiles(ByVal Folder As String, _
ByVal List As List(Of String))
Dim Items() As String = _
System.IO.Direc tory.GetFiles(F older)
ShowProgress(Fo lder, Items)
Application.DoE vents() '<-- Ops...
List.AddRange(I tems)
For Each SubFolder As String _
In System.IO.Direc tory.GetDirecto ries(Folder)
Try
LoadFiles(SubFo lder, List)
Catch Ex As Exception
End Try
Next
End Sub
</aircode>

As you can see, it's a recursive method that calls itself for each sub
folder. The 'Ops...' remark near DoEvents is just to remind you that
there are better ways to keep the UI alive during a long operation
(threads or the background worker, for instance). Anyway, this may
become your starting point...

HTH.

Regards,

Branco.

Mar 19 '07 #3
On Mon, 19 Mar 2007 08:28:02 -0700, "RobinS" <Ro****@NoSpam. yah.none>
wrote:
>I'm not really sure what your problem is, you never say, other than "I get
the clr warning message". That's not specific enough to provide you with
some help.
Sorry Robin. I thought that
>But with only the 25,000 files I currently have, I get the clr warning
message. I put the Application.DoE vents() in hoping to solve the
problem but it doesn't. So I stepped through the code and it is
hanging on the for each line.
was enough to show the problem, along with the code snippet, I was
having with the long running process timing out, and giving me the
message\warning . All I can say is I was extremely tired and apparently
wasn't thinking too clearly at the time. But the other reply seems to
be what I think I need to solve the problem. But thank you for trying.
>This has an example of using the background worker.

http://msdn2.microsoft.com/en-us/lib...undworker.aspx

Robin S.
Also, thank you very much for this link. I'm sure it will help me
understand what I was wanting to understand about the
backgroundworke r. I have an older version of the msdn installed on
here and, I guess, being tired, I simply didn't think to check the
online msdn for the info. The good thing, I went to bed shortly after,
which I should have done much sooner. Thank you very much for the
info.
---
Kyote
Mar 20 '07 #4
Thank you very very much Branco. This does indeed look like what I
need to solve the problem.

On 19 Mar 2007 14:27:29 -0700, "Branco Medeiros"
<br************ *@gmail.comwrot e:
><snip>

Before the loop enters its initial cicle, it will first have to grab
all the files from all sub folders off the base path you specified.
This is what I was having the trouble with. I had hoped there was
something I didn't know about that would allow me to do a DoEvents in
there. As I'm constantly finding situations where there are more
elegant and much simpler ways to accomplish some of the things I'm
writing code for.

>You can't put a DoEvents into this, cause it all will happen in the
GetFiles() instruction. Also, there's not much sense to put this in a
loop unless you want to do something with each file.
Thats exactly what I was doing. I was parsing the filenames, for each
file, into smaller segments. Then adding all bits dealing with that
filename into a class to store the parsed info. I was then adding each
class to a List.
>One possible way to execute what you want is just to assign the array
of file names directly to listOfFiles (which I assume is a List(Of
String)) or return it as an array.

Nevertheless , if you want to have some control over the loop, you may
consider loading the files folder by folder:

<aircode>
Sub LoadFiles(ByVal Folder As String, _
ByVal List As List(Of String))
Dim Items() As String = _
System.IO.Direc tory.GetFiles(F older)
ShowProgress(Fo lder, Items)
Application.DoE vents() '<-- Ops...
List.AddRange(I tems)
For Each SubFolder As String _
In System.IO.Direc tory.GetDirecto ries(Folder)
Try
LoadFiles(SubFo lder, List)
Catch Ex As Exception
End Try
Next
End Sub
</aircode>

As you can see, it's a recursive method that calls itself for each sub
folder. The 'Ops...' remark near DoEvents is just to remind you that
there are better ways to keep the UI alive during a long operation
(threads or the background worker, for instance). Anyway, this may
become your starting point...
I had initially started with something fairly similar to this. Then I
found a supposedly simpler way to do this and changed it around. But
that was back when I was only dealing with about 5,000-10,000
filenames. I completely forgot about it. Thank you for pointing it out
to me. This should solve the problem.
>Kyote wrote:
>I'm trying to make, what I thought, would be a simple application.

Join the club... =)))
LMAO, I'm happy to see it's not just me. Speaking of which, how do
you, more effectively, deal with program idea/concept improvements?

I often think of a simple app I'd like to make to simplify something I
want to do. Then while I'm writing away at it I get the 'Brillant'
idea for an improvement, or added feature. Something that can
'supposedly' make the app so much better than my original idea would
have been. But after a couple of those I sometimes get pretty confused
and frustrated.

Is there some kind of best practice or something for managing new
idea's/features? I guess I can stubbornly stick to my original app
specifications. Then once it's finished maybe then go back and revise
them. But is there a better way?
---
Kyote
Mar 20 '07 #5
Kyote wrote:
<snip>
I often think of a simple app I'd like to make to simplify something I
want to do. Then while I'm writing away at it I get the 'Brillant'
idea for an improvement, or added feature. Something that can
'supposedly' make the app so much better than my original idea would
have been. But after a couple of those I sometimes get pretty confused
and frustrated.
The pitfall of adding new (and usually unrelated) features before the
main goal has been achieved is a sure recipe to stall a project. I've
been tricked into this many times, seeing projects that were to last a
few months actually never see the light of day. An extreme example
was a team project here that never passed the glorified login screen,
with everybody getting lost in the multitude of options and features
the app was suppose to provide.

But this is specially tricky when you happen to be the developer,
manager *and* designer of the application, as often is the case here
at my current job.
Is there some kind of best practice or something for managing new
idea's/features? I guess I can stubbornly stick to my original app
specifications. Then once it's finished maybe then go back and revise
them. But is there a better way?
The KISS principle is valuable, to some extent (Keep It Simple,
Stupid). But you'll probably benefit more from formal approaches, such
as eXtreme Programming: test (yes, test before develop!), develop,
run. Rinse, refactor and repeat, adding more features.

I'm sure there are many more knowledgeable people here that can
provide advice on this...

Regards,

Branco.

Mar 20 '07 #6
It's not a problem. Apparently Branco was able to interpolate and figure
out what your warning message was. He's brilliant that way.

Good luck with the background worker.

Now go get some sleep. ;-)

Robin S.
-------------------------------------
"Kyote" <ky********@nos pamhotmail.comw rote in message
news:qp******** *************** *********@4ax.c om...
On Mon, 19 Mar 2007 08:28:02 -0700, "RobinS" <Ro****@NoSpam. yah.none>
wrote:
>>I'm not really sure what your problem is, you never say, other than "I
get
the clr warning message". That's not specific enough to provide you with
some help.

Sorry Robin. I thought that
>>But with only the 25,000 files I currently have, I get the clr warning
message. I put the Application.DoE vents() in hoping to solve the
problem but it doesn't. So I stepped through the code and it is
hanging on the for each line.
was enough to show the problem, along with the code snippet, I was
having with the long running process timing out, and giving me the
message\warning . All I can say is I was extremely tired and apparently
wasn't thinking too clearly at the time. But the other reply seems to
be what I think I need to solve the problem. But thank you for trying.
>>This has an example of using the background worker.

http://msdn2.microsoft.com/en-us/lib...undworker.aspx

Robin S.

Also, thank you very much for this link. I'm sure it will help me
understand what I was wanting to understand about the
backgroundworke r. I have an older version of the msdn installed on
here and, I guess, being tired, I simply didn't think to check the
online msdn for the info. The good thing, I went to bed shortly after,
which I should have done much sooner. Thank you very much for the
info.
---
Kyote

Mar 20 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
5464
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
1
6010
by: Anonieko | last post by:
Query: How to display progress bar for long running page Answer: Yet another solution. REFERENCE: http://www.eggheadcafe.com/articles/20050108.asp My only regret is that when click the browser back button, it loads the progress bar again. Any solution to this?
15
2569
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to determine who needs to receive the text message then send the message to the address. Only problem is, the employee may receive up to 4 of the same messages because each thread gets the recors then sends the message. I need somehow to prevent...
0
5558
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
4
2846
by: commander_coder | last post by:
Hello, I write a lot of CGI scripts, in Python of course. Now I need to convert some to long-running processes. I'm having trouble finding resources about the best practices to do that. I've found a lot of email discussions that say something like, "You need to educate yourself about the differences when you have long- running processes" but I've not had a lot of luck with finding things that explain the differences. I've seen some...
0
8435
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8768
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8547
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6186
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5655
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4181
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
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 we have to send another system
2
1754
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.