By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,521 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,521 IT Pros & Developers. It's quick & easy.

Creating listbox job/task queue

P: n/a
Hello,
For example i have listbox with 10 items.

how can i create a job queue (automated)? I used "for each" but after
processing 5 items, it stopped, why?

Thanks.

Oct 11 '07 #1
Share this Question
Share on Google+
10 Replies


P: n/a
On Oct 11, 7:11 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
Hello,
For example i have listbox with 10 items.

how can i create a job queue (automated)? I used "for each" but after
processing 5 items, it stopped, why?

Thanks.
Without you showing us any code it's very difficult to diagnose the
problem. My first guess is that you are removing the items from the
listbox in the foreach loop, which will modify the enumerator and
cause you to only process every-other item. But like I said, without
seeing your code it's difficult to say for sure.

Thanks,

Seth Rowe

Oct 11 '07 #2

P: n/a
Hi Seth,
In fact, i have listbox [too many topic i' opened recently :-) ] , and
the selected items of listbox is a parameter of my external process, i
want to create a "batch" processing program which process TILL the end
of listbox index NON-STOP/no user-prompt. Classic batch process of
programs on the earth :)

Dim psInfo As New System.Diagnostics.ProcessStartInfo("external.exe" ,
listbox1.selecteditem)
psInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Normal
psInfo.WorkingDirectory = Application.StartupPath
psInfo.WindowStyle = ProcessWindowStyle.Normal
Dim myProcess As Process =
System.Diagnostics.Process.Start(psInfo)
myProcess.WaitForExit()
If myProcess.HasExited = True Then
Try
Me.ListBox1.SelectedIndex =
Me.ListBox1.SelectedIndex + 1
System.Diagnostics.Process.Start("lame.exe", "
Catch
MsgBox("All files have been converted",
MsgBoxStyle.Information, "Done!")
End Try
But as you see after "try" , the program process the next item then it
stops as normal, but i want to do a batch process TILL the end of
listbox's ALL items. (all the listbox items, one by one).

I hope you understood.

Very thanks...

Oct 11 '07 #3

P: n/a
kimiraikkonen,

Have you tried using a For Next or a For Each loop?

Kerry Moorman
"kimiraikkonen" wrote:
Hi Seth,
In fact, i have listbox [too many topic i' opened recently :-) ] , and
the selected items of listbox is a parameter of my external process, i
want to create a "batch" processing program which process TILL the end
of listbox index NON-STOP/no user-prompt. Classic batch process of
programs on the earth :)

Dim psInfo As New System.Diagnostics.ProcessStartInfo("external.exe" ,
listbox1.selecteditem)
psInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Normal
psInfo.WorkingDirectory = Application.StartupPath
psInfo.WindowStyle = ProcessWindowStyle.Normal
Dim myProcess As Process =
System.Diagnostics.Process.Start(psInfo)
myProcess.WaitForExit()
If myProcess.HasExited = True Then
Try
Me.ListBox1.SelectedIndex =
Me.ListBox1.SelectedIndex + 1
System.Diagnostics.Process.Start("lame.exe", "
Catch
MsgBox("All files have been converted",
MsgBoxStyle.Information, "Done!")
End Try
But as you see after "try" , the program process the next item then it
stops as normal, but i want to do a batch process TILL the end of
listbox's ALL items. (all the listbox items, one by one).

I hope you understood.

Very thanks...

Oct 11 '07 #4

P: n/a
By the way, in your code you are misusing the "Catch" statement. Catch
is used to handle an exception, so in essence what you are doing is
telling the user that everything is finished whenever you have an
error.

Thanks,

Seth Rowe
Yes, but i know "catch" is used to handle exceptions, but i used
"catch" as informational because the error occurs due to finish of
listbox index. So calling it as "error" annoys user for nothing, the
reason of finishing of index.

For the codes which all the guys have posted, after i try i'll inform.

Very thanks for sharing codes, experiences...

Oct 11 '07 #5

P: n/a
but i used "catch" as informational because the error occurs due to
finish of listbox index.
ACK!!!!

Don't do that! Exceptions are very expensive to throw and catch and
should be avoided whenever possible. Instead you should be inspecting
the index value before trying to increment the SelectedIndex of the
ListBox. This way you know if an error would occur, and can prevent it
from happening.

Thanks,

Seth Rowe

Oct 11 '07 #6

P: n/a
On Oct 11, 5:53 pm, rowe_newsgroups <rowe_em...@yahoo.comwrote:
but i used "catch" as informational because the error occurs due to
finish of listbox index.

ACK!!!!

Don't do that! Exceptions are very expensive to throw and catch and
should be avoided whenever possible. Instead you should be inspecting
the index value before trying to increment the SelectedIndex of the
ListBox. This way you know if an error would occur, and can prevent it
from happening.

Thanks,

Seth Rowe
Seth, OK thanks for waning me, maybe you could put an informational
code block than indicates the program has reached the end of listbox
instead of "catch".

Thanks

kimiraikkonen

Oct 11 '07 #7

P: n/a
On Oct 11, 11:08 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Oct 11, 5:53 pm, rowe_newsgroups <rowe_em...@yahoo.comwrote:
but i used "catch" as informational because the error occurs due to
finish of listbox index.
ACK!!!!
Don't do that! Exceptions are very expensive to throw and catch and
should be avoided whenever possible. Instead you should be inspecting
the index value before trying to increment the SelectedIndex of the
ListBox. This way you know if an error would occur, and can prevent it
from happening.
Thanks,
Seth Rowe

Seth, OK thanks for waning me, maybe you could put an informational
code block than indicates the program has reached the end of listbox
instead of "catch".

Thanks

kimiraikkonen
If you look at the code I gave you, it already does this. As soon as
the while loop is finished (when the index exceeds or equals the
number of objects) it will display the same messagebox that you had in
the Catch block of your code.

Thanks,

Seth Rowe

Oct 11 '07 #8

P: n/a
This is a IMO a very bad idea. Generally you use a for each loop that
enumerates all elements or a value that gives the last index that should be
used (generally a property called "Count"," Length" etc... depending on what
you are using) so you are generally doing something like :

For i=0 To Elements.Count-1
' Do something with Elements(i)
Next

I would suggest to read at least once the language specification so that you
can familiarize yourself with language constructs. For example loops are at
:
http://msdn2.microsoft.com/en-us/lib...83(VS.71).aspx

--
Patrice

"kimiraikkonen" <ki*************@gmail.coma écrit dans le message de news:
11*********************@d55g2000hsg.googlegroups.c om...
>
>By the way, in your code you are misusing the "Catch" statement. Catch
is used to handle an exception, so in essence what you are doing is
telling the user that everything is finished whenever you have an
error.

Thanks,

Seth Rowe

Yes, but i know "catch" is used to handle exceptions, but i used
"catch" as informational because the error occurs due to finish of
listbox index. So calling it as "error" annoys user for nothing, the
reason of finishing of index.

For the codes which all the guys have posted, after i try i'll inform.

Very thanks for sharing codes, experiences...

Oct 11 '07 #9

P: n/a
On Oct 11, 9:53 am, rowe_newsgroups <rowe_em...@yahoo.comwrote:
Exceptions are very expensive to throw and catch and
While I agree about your advice on using exceptions, they are not as
expensive as you seem to indicate. See this article:

http://www.yoda.arachsys.com/csharp/exceptions.html

Cheers,

Chris

Oct 12 '07 #10

P: n/a
On Oct 11, 4:05 pm, Kerry Moorman
<KerryMoor...@discussions.microsoft.comwrote:
kimiraikkonen,

Have you tried using a For Next or a For Each loop?
Hi Kerry,

Could you define sample code for "for each loop"?
Seth, i'll try the code you've given.

Thanks both.

Oct 14 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.