473,652 Members | 3,132 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Queue.GetEnumer ator

Is there anything obvious wrong with this little loop? The second statement
throws an exception "Enumeratio n has not started. Call MoveNext." I thought
that is what I did in line one.

My intent here is to take what is left in the queue and write it back to the
text file from which it came so it can survive an upcoming reboot.

Do While myQ.GetEnumerat or.MoveNext

sw = myQ.GetEnumerat or.Current 'sw is a StreamWriter

Loop
Nov 20 '05 #1
9 4171
"Ty Moffett" <tm******@solar c.com> schrieb
Is there anything obvious wrong with this little loop? The second
statement throws an exception "Enumeratio n has not started. Call
MoveNext." I thought that is what I did in line one.

My intent here is to take what is left in the queue and write it back
to the text file from which it came so it can survive an upcoming
reboot.

Do While myQ.GetEnumerat or.MoveNext

sw = myQ.GetEnumerat or.Current 'sw is a StreamWriter

Loop


I guess, each call to GetEnumerator creates a _new_ enumerator. Solution:

dim en as ienuemrator

en = myQ.GetEnumerat or

Do While en.MoveNext
sw = em.Current 'sw is a StreamWriter
Loop
--
Armin

Nov 20 '05 #2
* "Ty Moffett" <tm******@solar c.com> scripsit:
Is there anything obvious wrong with this little loop? The second statement
throws an exception "Enumeratio n has not started. Call MoveNext." I thought
that is what I did in line one.

My intent here is to take what is left in the queue and write it back to the
text file from which it came so it can survive an upcoming reboot.
\\\
Dim e As IEnumerator = myQ.GetEnumerat or()
///
Do While myQ.GetEnumerat or.MoveNext
Instead of the line above:

\\\
Do While e.MoveNext()
///
sw = myQ.GetEnumerat or.Current 'sw is a StreamWriter
Use this instead of the line above:

\\\
sw = e.Current
///
Loop


--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Thanks a lot fellas. This little app is really coming along.

I did fnd that sw.WriteLine(en .Current) worked like I wanted it too.

Thanks again!

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:bn******** ****@ID-208219.news.uni-berlin.de...
* "Ty Moffett" <tm******@solar c.com> scripsit:
Is there anything obvious wrong with this little loop? The second statement throws an exception "Enumeratio n has not started. Call MoveNext." I thought that is what I did in line one.

My intent here is to take what is left in the queue and write it back to the text file from which it came so it can survive an upcoming reboot.


\\\
Dim e As IEnumerator = myQ.GetEnumerat or()
///
Do While myQ.GetEnumerat or.MoveNext


Instead of the line above:

\\\
Do While e.MoveNext()
///
sw = myQ.GetEnumerat or.Current 'sw is a StreamWriter


Use this instead of the line above:

\\\
sw = e.Current
///
Loop


--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #4
In article <ub************ **@TK2MSFTNGP10 .phx.gbl>, Armin Zingler wrote:
"Ty Moffett" <tm******@solar c.com> schrieb
Is there anything obvious wrong with this little loop? The second
statement throws an exception "Enumeratio n has not started. Call
MoveNext." I thought that is what I did in line one.

My intent here is to take what is left in the queue and write it back
to the text file from which it came so it can survive an upcoming
reboot.

Do While myQ.GetEnumerat or.MoveNext

sw = myQ.GetEnumerat or.Current 'sw is a StreamWriter

Loop


I guess, each call to GetEnumerator creates a _new_ enumerator. Solution:

dim en as ienuemrator

en = myQ.GetEnumerat or

Do While en.MoveNext
sw = em.Current 'sw is a StreamWriter
Loop


I have to ask... Why don't you just use a For Each?

Dim q As Queue(New String() {"1", "2", "3", "4", "5"}
For Each s As String In q
Console.WriteLi ne(s)
Next

Unless your trying to actually modify the collection (like calling
Enqueue or Dequeue), that should work fine. And if you are trying to
modify the collection, then you shouldn't use the enumerator anyway
because it's going to throw an exception. In that case, you should just
do something like:

Do While q.Count > 0
s = DirectCast(q.De queue(), String)
Console.WriteLi ne(s)
Loop
--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #5
Ty,
Why are using a While loop instead of a For Next?

As Armin stated, each call to GetEnumertor returns a new IEnumerator object,
as you have multiple threads and each thread can be enumerating over the
same collection, or even have a single thread & can be enumerating over the
same collection with multiple IEnumerator variables.

I would recommend you use a For Each:

' VS.NET 2003 syntax
For Each item As Object In myQ
sw.WriteLine(it em)
Next

Hope this helps
Jay

"Ty Moffett" <tm******@solar c.com> wrote in message
news:uu******** ********@TK2MSF TNGP10.phx.gbl. ..
Is there anything obvious wrong with this little loop? The second statement throws an exception "Enumeratio n has not started. Call MoveNext." I thought that is what I did in line one.

My intent here is to take what is left in the queue and write it back to the text file from which it came so it can survive an upcoming reboot.

Do While myQ.GetEnumerat or.MoveNext

sw = myQ.GetEnumerat or.Current 'sw is a StreamWriter

Loop

Nov 20 '05 #6
"Tom Shelton" <to*@mtogden.co m> schrieb
I guess, each call to GetEnumerator creates a _new_ enumerator.
Solution:

dim en as ienuemrator

en = myQ.GetEnumerat or

Do While en.MoveNext
sw = em.Current 'sw is a StreamWriter
Loop


I have to ask... Why don't you just use a For Each?


Because Ty Moffett also didn't. Of course I could also point him to For
each, but I wanted to show why the error occurs.
--
Armin

Nov 20 '05 #7
On 2003-10-23, Armin Zingler <az*******@free net.de> wrote:
"Tom Shelton" <to*@mtogden.co m> schrieb
> I guess, each call to GetEnumerator creates a _new_ enumerator.
> Solution:
>
> dim en as ienuemrator
>
> en = myQ.GetEnumerat or
>
> Do While en.MoveNext
> sw = em.Current 'sw is a StreamWriter
> Loop
>
>


I have to ask... Why don't you just use a For Each?


Because Ty Moffett also didn't. Of course I could also point him to For
each, but I wanted to show why the error occurs.


Sorry, Armin... My post was acutally supposed to be attached to Ty's
but I some how muffed it... I realize you were just showing him how it
works. Gosh, that's the second time today that I've felt sheepish. I
think I better take a day off :)

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #8
"Tom Shelton" <to*@mtogden.co m> schrieb
Sorry, Armin... My post was acutally supposed to be attached to
Ty's but I some how muffed it... I realize you were just showing him
how it works.

No problem. Happens to everyone now and then. :-)
Gosh, that's the second time today that I've felt
sheepish. I think I better take a day off :)


Sometimes I think we all should take a day off. ;-)

--
Armin

Nov 20 '05 #9
Mainly just out of ignorance. =) I'm going to take your advice and try to
simplify my code.

Thanks a lot for all of you help guys. =)

"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Ty,
Why are using a While loop instead of a For Next?

As Armin stated, each call to GetEnumertor returns a new IEnumerator object, as you have multiple threads and each thread can be enumerating over the
same collection, or even have a single thread & can be enumerating over the same collection with multiple IEnumerator variables.

I would recommend you use a For Each:

' VS.NET 2003 syntax
For Each item As Object In myQ
sw.WriteLine(it em)
Next

Hope this helps
Jay

"Ty Moffett" <tm******@solar c.com> wrote in message
news:uu******** ********@TK2MSF TNGP10.phx.gbl. ..
Is there anything obvious wrong with this little loop? The second

statement
throws an exception "Enumeratio n has not started. Call MoveNext." I

thought
that is what I did in line one.

My intent here is to take what is left in the queue and write it back to

the
text file from which it came so it can survive an upcoming reboot.

Do While myQ.GetEnumerat or.MoveNext

sw = myQ.GetEnumerat or.Current 'sw is a StreamWriter

Loop


Nov 20 '05 #10

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

Similar topics

1
4913
by: Kevin P. Fleming | last post by:
ArrayList implements an overload for IEnumerator's GetEnumerator method as follows: GetEnumerator(int offset, int count) However, I can't see a way to take advantage of this, even though I'd like to... I'd like to be able to use foreach to iterate over a section of the ArrayList, but can't find any syntax that will work. The obvious: foreach char ch in arList(0,20)
4
5080
by: John C | last post by:
I'm new to C#, so just point me at the correct reference material if this question has been answered before. When creating a new class which implements the IDictionary interface, two versions of the GetEnumerator method must be defined (one from the IDictionary interface, one from the IEnumerable interface). The first is defined as: public IDictionaryEnumerator GetEnumerator()
2
1557
by: Sam Marrocco | last post by:
I've constructed a class that inherits the NameObjectCollectionBase class. All works well, but I'd like to shadow the GetEnumerator method so that it returns an actual value *instead of a DictionaryEntry*. I've gotten strange errors when attempting to override GetEnumerator, such as 'GetEnumerator() cannot override 'Public Overridable NotOverridable Function GetEnumerator() because it is declared NotOverridable......yes, it actually...
4
8179
by: nhmark64 | last post by:
Hi, Does System.Collections.Generic.Queue not have a Synchronized method because it is already in effect synchronized, or is the Synchronized functionality missing from System.Collections.Generic.Queue? Putting it another way can I safely replace a System.Collections.Queue.Synchronized(myUnSynchronizedQueue) with a System.Collections.Generic.Queue while porting a working 2003 project? Thanks,
2
19859
by: Steve Richter | last post by:
very confused on how to implement the IEnumerable and IEnumerator interfaces on a generic type. I understand I should just use a foreach loop in the GetEnumerator method and use "yield return", etc. would like to know how implement my generic GetEnumerator to yield return an interface to IEnumerator<T>. I am getting a compile error that reminds me a lot of C++ template programming. thanks,
3
3734
by: =?Utf-8?B?cmNoZg==?= | last post by:
I know this is simple problem but I am so new that there is some fundamental disconnect in my understanding of: Enumerable, Enumerator, and Generics. As a result I am having a problem debugging this error message "Error 1 'SimpleSite.Email.Model.Hosts' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'SimpleSite.Email.Model.Hosts.GetEnumerator()' is either static, not public, or has the wrong return...
2
1366
by: =?Utf-8?B?VGVk?= | last post by:
I have been asked to change an existing program which Implemented a Collection Class The current class had what is below (its just a summary of the code) Public Class FieldList Implements System.Collections.IEnumerable Private thisColl As Collection
16
4261
by: colin | last post by:
Hi, is it possible to have a recursive GetEnumerator for traversing a tree structure ? public IEnumerator<DTypeGetEnumerator() { return GetEnumerator(root);
2
2173
by: Tony | last post by:
Hello! According to the documentation we have the following interface IList : ICollection, IEnumerable { I can understand all the methods in this IList } interface ICollection : IEnumerable {
0
8367
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...
1
8467
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,...
0
7302
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5619
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
4145
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
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
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
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
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.