Lambda problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Lambda problem

  1. #1
    Join Date
    Dec 2009
    Posts
    596

    Lambda problem

    Good morning everyone. I'm having a problem with this code that I'm trying to understand. I get a red wiggly line under the word "proxy.BeginAdd(" , this looks really wierd in that the closing parentheses is missing. It looks like a typo but since this is lambda and i don't know squat about lambda maybe this is legal? Can any of you guys guess at how this is supposed to be written if it is a typo? Or can you tell me what was the meant writing? Just placing a closing parenthesese around => didn't fix it. Also I don't know what "ar" is or where it's coming from either. Can someone please take a look at this and give me a hand?

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    using MathClient.ServiceReference1;
    using System.Threading;
    
    namespace MathClient
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("***** The Async Math Client *****\n");
    
                using (BasicMathClient proxy = new BasicMathClient())
                {
                    proxy.Open();
    
                    //add numbers in an async manner, using a lambda expression.
                    IAsyncResult result = proxy.BeginAdd(2, 3,      //red squiggly line under proxy.BeginAdd(
                                            ar =>
                            {
                                Console.WriteLine("2 + 5 = {0}, proxy.EndAdd(ar));
                            }
                            while (!result.IsCompleted)
                            {
                                Thread.Sleep(200);
                                Console.WriteLine("Client working...");
                            }
                    Console.ReadLine();
                }
            }
        }
    }

  2. #2
    Join Date
    Jul 2005
    Location
    Louisville, KY
    Posts
    201

    Re: Lambda problem

    The BeginAdd function takes 4 parameters. See the following:

    Code:
    IAsyncResult result = proxy.BeginAdd(2, 3, MyCallback, proxy);
    If you didn't have a callback, put null. For additional help, with the callback, see http://med-adel.blogspot.com/2010/10...-wcf-part.html.

    If this solution resolves your problem, please rate this post, and mark the thread resolved!

    Regards,
    Quinn

  3. #3
    Join Date
    Dec 2009
    Posts
    596

    Re: Lambda problem

    Hi there. Thanks a lot. It goes like this now and everything works.

    Code:
     static void Main(string[] args)
            {
                Console.WriteLine("***** The Async Math Client *****\n");
    
                using (BasicMathClient proxy = new BasicMathClient())
                {
                    proxy.Open();
    
                    //add numbers in an async manner, using a lambda expression.
                    IAsyncResult result = proxy.BeginAdd(2, 3, 
                           ar =>
                            {
                                Console.WriteLine("2 + 5 = {0}", proxy.EndAdd(ar));
                            },null);
                            while (!result.IsCompleted)
                            {
                                Thread.Sleep(200);
                                Console.WriteLine("Client working...");
                            }
                    Console.ReadLine();
                }
            }

  4. #4
    Join Date
    Jul 2005
    Location
    Louisville, KY
    Posts
    201

    Re: Lambda problem

    Glad I could help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center