delegates

difference between asynchronous calls and asynchronous io calls in .net

Using a delegate I can call any function asynchronously. From the documentation I understand this is done by queueing a workitem for the threadpool. One can also do asynchronous calls to IO functions (like reading from sockets, files, webpages, etc). I think (but I'm not sure) this does NOT spawn a workitem in the threadpool. Only after...

What's the difference between following code for adding new events

-- If I define an event with an inital empty delegate I don't need to check for null class MyClass { public event EventHandler<MyEventArgs> MyEvent = delegate { }; void SomeMethod() { ... MyEvent(); // No need to check for null ... } } -- Otherwise I need to check for null class MyClass { public event EventHandler<MyEvent...

I want to be able to use a lambda expression to specify a range of values to return over a wcf service

I have no idea if this is possible ... but it would be cool. the question is whether it is possible but then a bit of an example if possible. I am not sure what method signature you would use to pass the lambda expression into. Eg the method IList<Group> GetGroups() How would you modify that to be able to pass a lambda expression into...

What am I missing in this chain of predicates?

NOTE: Right before posting this question it occurred to me there's a better way of doing what I was trying to accomplish (and I feel pretty stupid about it): IEnumerable<string> checkedItems = ProductTypesList.CheckedItems.Cast<string>(); filter = p => checkedItems.Contains(p.ProductType); So OK, yes, I already realize this. However, ...

Explain introductory timing of Action<T> versus Func<T,TResult> Delegates

Why was Func<T, TResult>(..) introduced with .NET 3.0 whereas Action<T>(..) with .NET 2.0? Edit: I'm coding a project in .NET 2.0 right now and am missing Func. Although it's easy to roll your own as mentioned in the comments and answers i.e. simple delegate TResult Func<T,TResult>(T); I am curious why the timing would be different with...

Invoke delegate question

Hello, I would like to know about the Invoke(delegate) method. I do not understand why I do not need to specify arguments. What if I need them supply..Hopefully below you better understand what I mean. Thank you EventHandler a = new EventHandler(this.A); Invoke(a); //where doest it take the arguments from? a();...

C# Events between threads executed in their own thread (How to) ?

Hello, I'd like to have two Threads. Let's call them : Thread A Thread B Thread A fires an event and thread B listen to this event. When the Thread B Event Listener is executed, it's executed with the Thread A's thread ID, so i guess it is executed within the Thread A. What I'd like to do is be able to fire event to Thread B sayin...

Passing a value from a WPF page to its parent's window

Hi, I am hoping for some guidence. I have a wpf application that contains a window (Window1) and a page (Page1). The page is inside the window using a frame. I have a button within the page that I want to be able to press and pass a string value back to mainwindow and display it within a label. Can anyone help with a basic example as I...

Getting run-time value of a ParameterExpression in a expression tree

I am missing the obvious: How do I access the value of a parameter inside a lambda expression expression tree? Scenario: For a delegate x I dynamically create a lambda expression with an expression tree body which has the same signature as the delegate x. Inside the lamdba's body, I do some validation, checking, logging stuff (this is ...

Cross platform C++ code architecture

I'm having a bit of a go at developing a platform abstraction library for an application I'm writing, and struggling to come up with a neat way of separating my platform independent code from the platform specific code. As I see it there are two basic approaches possible: platform independent classes with platform specific delegates, or...

App crashing when setting delegate and datasoruce

If I want to set my delegate and datasource for my uitableview my app crashes. What I'm doing wrong? - (void)loadView { NSLog(@"AddListViewController"); ShareListViewController *shareListViewController = [[ShareListViewController alloc] init]; UITableView *shareListView = [[UITableView alloc]initWithFrame:CGRectMake(100, 30, 100, ...

How can I pass a mouse-click method as a parameter?

I want to make an extension method which fills a stackpanel with buttons. In order to do this I have to pass in a mouse-click-handler. What type does the mouseClickHandler parameter have to be here? I know it's something like these but they all don't work: delegate Func<object, RoutedEventArgs> Action<> Code: public static void F...

JQuery delegate method not working

I am trying to use the delegate method on a grid that I wrap with the DataTables.Net plug-in. I originally had this code which works as expected. $("#myGrid tbody tr").click(function() { var id = $(this).children('td').eq(0).text(); alert(id); }); However, if I change the paging size then the newer rows don't h...

Create generic delegate using reflection

I have the following code: class Program { static void Main(string[] args) { new Program().Run(); } public void Run() { // works Func<IEnumerable<int>> static_delegate = new Func<IEnumerable<int>>(SomeMethod<String>); MethodInfo mi = this.GetType().GetMethod("SomeMethod").MakeGeneri...

parse delegate to string query c#.net

Hi! I want to implement simple LINQ-to-SQL-like functionality in my .net application. For example i have the following code: userAccounts.Where(ua=>ua.Name=="User1"); and i want delegate in Where method to create a string like this "name = 'User1'". How it can be done? Thanks. ...

C# - declare method in argument (delegate)

Hello, In the code below I pass method B as an action to be perfomed on on the objects in the IterateObjects method. I would like to ask whether I can explicitly declare the method in the argument instead of passing it by name, something like this: a.IterateObjects(delegate void(string s){//method body}) Its not correct but I am sure I ...

Action<T> vs anonymous method question

Hi, I had a question answered which raised another one, why following does not work? I do not understand it. The compiler says: Cannot convert anonymous method do string. But why? public List<string> list = new List<string>(); private void Form1_Load(object sender, EventArgs e) { a.IterateObjects(B); // w...

Applied delegating and protocols

Hello, I am trying to figure out the reason why I should learn these things about delegates and protocols. First I thought that it was necessary in order to create nice(er) design of the code. Then I started to read and I cannot really find the reasons I though that I was going to find (That is, "good" reasons...). When should I apply ...

Code Complete 2ed, composition and delegation.

Hi there. After a couple of weeks reading on this forum I thought it was time for me to do my first post. I'm currently rereading Code Complete. I think it's 15 years since the last time, and I find that I still can't write code ;-) Anyway on page 138 in Code Complete you find this coding horror example. (I have removed some of the ...

Generic delegate instances

I wonder if C# (or the underlying .NET framework) supports some kind of "generic delegate instances": that is a delegate instance that still has an unresolved type parameter, to be resolved at the time the delegate is invoked (not at the time the delegate is created). I suspect this isn't possible, but I'm asking it anyway... Here is an...