Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 702221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:41:48+00:00 2026-05-14T03:41:48+00:00

Note that I’m aware of other yield in vb.net questions here on SO. I’m

  • 0

Note that I’m aware of other yield in vb.net questions here on SO.

I’m playing around with Caliburn lately. Bunch of great stuff there, including co-routines implementation.

Most of the work I’m doing is C# based, but now I’m also creating an architecture guideline for a VB.NET only shop, based on Rob’s small MVVM framework.

Everything looks very well except using co-routines from VB. Since VB 10 is used, we can try something like Bill McCarthy’s suggestion:

Public Function Lines(ByVal rdr as TextReader) As IEnumerable(Of String)
     Return New GenericIterator(Of String) 
          (Function(ByRef nextItem As String) As Boolean
              nextItem = rdr.ReadLine
              Return nextItem IsNot Nothing
           End Function)
End Function

I’m just failing to comprehend how a little more complex co-routine method like the one below (taken from Rob’s GameLibrary) could be written in VB:

public IEnumerable<IResult> ExecuteSearch()
{
    var search = new SearchGames
    {
        SearchText = SearchText
    }.AsResult();

    yield return Show.Busy();
    yield return search;

    var resultCount = search.Response.Count();

    if (resultCount == 0)
        SearchResults = _noResults.WithTitle(SearchText);
    else if (resultCount == 1 && search.Response.First().Title == SearchText)
    {
        var getGame = new GetGame
        {
            Id = search.Response.First().Id
        }.AsResult();

        yield return getGame;
        yield return Show.Screen<ExploreGameViewModel>()
            .Configured(x => x.WithGame(getGame.Response));
    }
    else SearchResults = _results.With(search.Response);

    yield return Show.NotBusy();
}

Any idea how to achieve that, or any thoughts on using Caliburn co-routines in VB?


Edit:

Marco pointed me to a right direction. After looking in Reflector – Visual Basic code of Rob’s GameLibrary, I managed to modify Bill McCarthy’s GenericIterator to become a poor man’s state machine:

Private _state As Integer = -1

Public Function MoveNext() As Boolean Implements IEnumerator.MoveNext
    _state += 1
    Return _func(_Current, _state)
End Function

And we can use it like this:

Public Function ExecuteSearch() As IEnumerable(Of String)
    ' If we need some variable shared across states, define it here
    Dim someSharedStuff As String = String.Empty

    ' Notice the second lambda function parameter below - state
    Return New GenericIterator(Of IResult) 
        (Function(ByRef nextItem As IResult, state As Integer) As Boolean
            Select Case state
                Case 0
                    someSharedStuff = "First state"
                    nextItem = Show.Busy
                    Return True
                Case 1
                    nextItem = Show.SomeLoadingScreen
                    ' Do some additional processing here...
                    Return True
                Case 2
                    ' Do something with someSharedStuff variable...
                    Console.WriteLine(someSharedStuff)
                    nextItem = PerforSomemWebServiceCall()
                    Return True
                '...
                Case 6
                    nextItem = Show.NotBusy
                    Return False
            End Select

            Return False
         End Function)

End Function

It definitely isn’t as elegant as C# version, but it looks to be doable. We’ll see if there are any problems with this. If anyone has better idea, I’m all ears.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:41:48+00:00Added an answer on May 14, 2026 at 3:41 am

    As far I understand, the VB workaround relies on the uniformity of the various steps; in other words, it repeats the same action until the exit condition is met.

    Caliburn co-routines, instead, are useful in the opposite scenario: unhomogeneous (and asynchronous) steps interlaced with control code; but this is basically a state machine.

    Actually, Caliburn leverages C# compiler to obtain a free and automatically generated state machine implementation; so the solution might be to build a simple hand-made state machine just like the one built by C# compiler (see http://blogs.msdn.com/wesdyer/archive/2007/03/23/all-about-iterators.aspx).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NOTE: Before reading this question please note that I have read the previous questions
Note that I'm mirroring the example given here very closely. In fact, my situation
Please note that my experience in Silverlight/.Net and WCF is about two weeks of
Note that I'm 95% unfamiliar with pointers. So here's my dilemma, I have a
I'm having a problem with matching against french accented characters (note that other different
Note that I'm not actually doing anything with a database here, so ORM tools
Please note that I have seen a similar query here , but think my
Please note that, I don't have any control over the target file. Some other
Note that I'm not talking about the compiler-generated Temporary ASP.NET Files. My web application
Please note that the scenario is ASP.NET Webforms + Master - Content page which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.