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

  • SEARCH
  • Home
  • 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 8578583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:25:26+00:00 2026-06-11T20:25:26+00:00

I am sending several messages over a websocket inside of a callback. The problem

  • 0

I am sending several messages over a websocket inside of a callback. The problem is, that if one sending is not completed and another one is started the function exceeds with an exception. Due to socket.SendAsync() is async I could wait for it with await. As soon as I am using await I will have to declare my lambda expression as async. But as soon as I do this the callback is never called. Does anyone know why or do have a solution/workaround for this?

Example code:

queue.QueueCompleted += async (s, eA) =>
    {
        z = dr.Start + 1;
        while (z < (dr.Start + 1 + dr.Limit))
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + @"DCM\" + dr.Code.Replace('.', '_') + @"\IMAGE" + z.ToString() + ".jpg";
            Image image = null;
            image = Image.FromFile(path);
            ImageConverter ic = new ImageConverter();
            byte[] buffer = (byte[])ic.ConvertTo(image, typeof(byte[]));
            try
            {
                if (socket != null && socket.State == WebSocketState.Open)
                {
                    Debug.WriteLine("REACHED");
                    await socket.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Binary, true, CancellationToken.None);
                    image.Dispose();
                }
            }
            catch (Exception e)
            {
                image.Dispose();
                break;
            }
            z++;
        }
    };

The callback is a simple EventHandler and is called like if(QueueCompleted != null) QueueCompleted(e, null);

  • 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-06-11T20:25:28+00:00Added an answer on June 11, 2026 at 8:25 pm

    Probably not the most efficient, but here’s a pattern I use for inline async code:

    queue.QueueCompleted += (s, eA) =>
                {
                    Task.Run(async ()=>{
                        //blah
                    });
                };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am sending several messages in my application from client to server one of
When sending data from one iOS device to another, I receive these errors. 2012-06-21
We have a scripting engine (running under Windows) that launches another application several thousand
In our backend there are several services that send and receive messages via JMS
I have several different c# worker applications that run various continuous tasks: sending emails
I have got WCF service allowing sending messages between several users in LAN -
When sending uncontrolled amounts of TextWebSocketFrames to a simple Netty WebSocket echo server implementation
I have a problem handling messages in a Thread. My run-method looks like this
When sending messages from a self hosted WCF service to many clients (about 10
I am trying to implement a (T)LV protocol over TCP sending protocol buffers from

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.