-
October 14th, 2011, 09:34 AM
#1
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();
}
}
}
}
-
October 14th, 2011, 12:39 PM
#2
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
-
October 14th, 2011, 03:00 PM
#3
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();
}
}
-
October 14th, 2011, 05:06 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|