Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
some code here

C#
Action<string> messagetarget;
messagetarget = delegate(string s) { showmessage(s); };
//this.Invoke(messagetarget);


and some code here

C#
public void showmessage(string thid1)
{
    lvc[0] = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
    lvc[1] = thid1;
    listView2.Items.Add(new ListViewItem(lvc, 0));
}


and if a write this code a got an error

C#
    Action<string> messagetarget;
    messagetarget = delegate(string s, string t) { showmessage(s, t); };
    this.Invoke(messagetarget);

public void showmessage(string thid1,string message1)
{
    lvc[0] = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
    lvc[1] = thid1;
    lvc[2] = message1;
    listView2.Items.Add(new ListViewItem(lvc, 0));
}


i got an error:

Error 10 Delegate 'System.Action<string>' does not take 2 arguments C:\Users\bibo\Desktop\KryptonFormProject1\KryptonFormProject1\Form1.cs 223 29 KryptonFormProject1

can you explain me what can i do ??
Posted
Updated 15-May-11 1:22am
v2

Look at your declaration for messagetarget - there's only one parameter, and you're trying to pass the delegate two parameters.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-May-11 12:57pm    
This is the answer, my 5.
--SA
Kim Togo 15-May-11 13:45pm    
Good answer.
Change
C#
Action<string> messagetarget
to
C#
Action<string,string> messagetarget


See Action<T1, T2> Delegate[^]
 
Share this answer
 
v2
Comments
guendouz bachir 15-May-11 9:07am    
no, it can't work see http://data.imagup.com/8/1120130185.0516%20140125_001png
Ed Nutting 15-May-11 9:14am    
Clearly it can work the OP is just doing something wrong, though how on earth anyone's supposed to know what from his lack of detail. Good answer for what was given, my 5 :)
Kim Togo 15-May-11 13:42pm    
Thanks.
guendouz bachir 15-May-11 12:37pm    
where is the probleme ??
http://data.imagup.com/8/1120130185.0516%20140125_001png
Sergey Alexandrovich Kryukov 15-May-11 13:00pm    
Correct answer, my 5.
As to real help, it's hard to say, I feel OP does not have sufficient understanding of generic and/or delegate and/or Invoke. I have no idea why such strange code, what the purpose could be.

@guendouz bachir: changes are, you don't need this code in first place.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900