473,577 Members | 3,256 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot convert lambda expression of type System.delegate becauseit is not a delegate type


When i compile this function I get the error Cannot convert lambda
expression of type System.delegate because it is not a delegate type.

private void SetStatus(strin g status)
{
if (this.InvokeReq uired)
{
this.Invoke( status =SetStatus(stat us));
}
else
{
toolStripStatus Label1.Text = status;
}
}

Is it not possible to use the lambda expression in this case? Do I have
to declare a delegate and use it like the old way?
Jun 27 '08 #1
5 5699
Satish wrote:
>
When i compile this function I get the error Cannot convert lambda
expression of type System.delegate because it is not a delegate type.

private void SetStatus(strin g status)
{
if (this.InvokeReq uired)
{
this.Invoke( status =SetStatus(stat us));
What type is 'this'? How does the signature of 'Invoke' look?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 27 '08 #2
The code is on a windows Form so this is System.Windows. Form. My
intention is to update the status bar on the Form from a background thread.

Martin Honnen wrote:
Satish wrote:
> When i compile this function I get the error Cannot convert
lambda expression of type System.delegate because it is not a delegate
type.

private void SetStatus(strin g status)
{
if (this.InvokeReq uired)
{
this.Invoke( status =SetStatus(stat us));

What type is 'this'? How does the signature of 'Invoke' look?
Jun 27 '08 #3
First - both lambdas and anonymous method must be typed; in this case,
MethodInvoker or Action is the easiest...

You'd probably find that this works:

this.Invoke((Ac tion) (() =SetStatus(stat us)));

But to be honest, it is just as easy to use anon-methods here:

this.Invoke((Ac tion) delegate {SetStatus(stat us);});
Jun 27 '08 #4
And a third syntax:

this.Invoke((Ac tion<string>)Se tStatus, status);

i.e.
treat SetStatus as a void method that accepts a string, and invoke it,
passing /status/ as the arg.

Marc
Jun 27 '08 #5
Thanks it worked!!

Marc Gravell wrote:
And a third syntax:

this.Invoke((Ac tion<string>)Se tStatus, status);

i.e.
treat SetStatus as a void method that accepts a string, and invoke it,
passing /status/ as the arg.

Marc
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7471
by: Patrick Dugan | last post by:
I am *trying* to convert a VB6 program to vb.net. One error I am getting that I cannot figure out is: 'AddressOf' expression cannot be converted to 'Integer' because 'Integer' is not a delegate type. This is the offending line where the error is located: res = UUIRTSetReceiveCallback(hDrvHandle, AddressOf IRReceiveCallback, Me)
5
3774
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public List<RoleData> GetRoles() { return GetRoles(null, false); }
2
2193
by: =?Utf-8?B?UnV0aCBNYXJr?= | last post by:
Hey, Am trying to write a lambda expression for a delegate, am getting an error as ------------------------------ only assignment, call, increment, decrement, and new expression can be used as a statement ----------------------------- For the following code.
20
3969
by: raylopez99 | last post by:
Took a look at all the fuss about "lambda expressions" from Jon Skeet's excellent book "C# in Depth". Jon has an example, reproduced below (excerpt) on lambda expressions. My n00b take: it's like SQL and those 'high level' languages that try to be too clever by half and pack a lot of syntax in as short a space as possible. Like Egyptian...
0
1225
by: Pavel Minaev | last post by:
On Aug 14, 1:37 pm, raylopez99 <raylope...@yahoo.comwrote: You are, of course, entitled to your opinion, but lambdas are a part of C# 3.0, and any C# developer has to know their ins and outs if only to be able to maintain other people's code. Also, every time I hear such sentiments - "generics/closures/type inference/... are hard to...
16
1738
by: rowe_newsgroups | last post by:
Ok, I'm tired and I'm sure I know the answer to this, but I can't seem to come up with it right now. What is the VB.NET equivalent to the following C# code? ///////////// Action<FooClassmethod = x =x.FooSub(null); ///////////// Where 'FooSub' is a sub (not a function) and therefore doesn't return
6
2300
by: Stefan Hoffmann | last post by:
hi @all, I stumbled upon this one: MethodInvoker listMethodInvoker = () =list = Broker.RetrieveList<T>(); This works fine for me under VS2008 and target .Net 2.0. The question is: Why?
3
221
by: Marc Gravell | last post by:
A lambda expression is a short form to write a delegate In /this/ case (LINQ-to-Objects): yes - but it could equally be compiled to an Expression, which is very, very different. A lambda *statement*, on the other hand, is always a delegate. Marc
11
1677
by: puzzlecracker | last post by:
I am not understanding what's happening in the code below (from accelerated c#) -- I know what the outcome but not how .net does it: using System; using System.Linq; public class LambdaTest { static void Main()
0
7845
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8286
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8143
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6517
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2287
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1385
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1107
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.