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 930961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:25:26+00:00 2026-05-15T20:25:26+00:00

The following code was a proof of concept for a message batching routine. Do

  • 0

The following code was a proof of concept for a message batching routine. Do I avoid goto like the plague and rewrite this code? Or do you think the goto is an expressive way to get this done?

If you’d rewrite please post some code…

var queue = new Queue<TraceItem>(this.batch);
while (this.connected)
{
    byte[] buffer = null;
    try
    {
        socket.Recv(out buffer);
    }
    catch
    {
        // ignore the exception we get when the socket is shut down from another thread
        // the connected flag will be set to false and we'll break the loop
    }

HaveAnotherMessage:
    if (buffer != null)
    {
        try
        {
            var item = TraceItemSerializer.FromBytes(buffer);
            if (item != null)
            {
                queue.Enqueue(item);

                buffer = null;
                if (queue.Count < this.batch && socket.Recv(out buffer, ZMQ.NOBLOCK))
                {
                    goto HaveAnotherMessage;
                }
            }
        }
        catch (Exception ex)
        {
            this.ReceiverPerformanceCounter.IncrementDiagnosticExceptions();
            this.tracer.TraceException(TraceEventType.Error, 0, ex);
        }
    }

    // queue processing code
}
  • 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-15T20:25:26+00:00Added an answer on May 15, 2026 at 8:25 pm

    Replace the goto with a do-while, or simply a while loop if you don’t want the “always run once” functionality you have right now.

    var queue = new Queue<TraceItem>(this.batch);
    while (this.connected)
    {
        byte[] buffer = null;
        try
        {
            socket.Recv(out buffer);
        }
        catch
        {
            // ignore the exception we get when the socket is shut down from another thread
            // the connected flag will be set to false and we'll break the loop
        }
    
        do {
            if (buffer != null)
            {
                try
                {
                    var item = TraceItemSerializer.FromBytes(buffer);
                    if (item != null)
                    {
                        queue.Enqueue(item);
                        buffer = null;
                    }
                }
                catch (Exception ex)
                {
                    this.ReceiverPerformanceCounter.IncrementDiagnosticExceptions();
                    this.tracer.TraceException(TraceEventType.Error, 0, ex);
                }
            }
        } while(queue.Count < this.batch && socket.Recv(out buffer, ZMQ.NOBLOCK))
    
        // queue processing code
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to run the following code, as a proof of concept, and
I am using the following code as a proof-of concept for parsing the FCC
I'm using the following code snippet as a proof of concept to sync scrollbars
So I have the following code in /[my-theme-name]/template/catalog/navigation/left.phtml as a proof of concept: <?php
I'm trying to use the following code (poorly written, but it's just a proof
Following code takes like 2500 milliseconds on an i7-*3.4 GHz windows-7 64-bit computer to
This is proof of concept project - The goal is to create an application
I am working on proof-of-concept code to dynamically generate CAML based on keywords provided
The background to this question is the following: Hash code for expandable class (future
I'm trying to implement messaging between my ViewModels My Proof of Concept Code is

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.