delegates

Examples of Asynchronous Interaction in C#.Net?!

I know that it's possible to implicitly provide asynchronous interaction using: Asynchronous Delegates Asynchronous Callbacks I was just wondering what other methods .Net supports for asynchronous interaction? Help greatly appreciated. Regards EDIT: Maybe I didn't explain myself correctly.... I UNDERSTAND THREADING AND CONCURRENC...

Create .NET Custom Control Button for CRUD

Hello there, I am thinking to create a Custom Control button that would do a CRUD tasks for me. Let me elaborate: I wanted something that save time to writeup code on every UI for CRUD tasks. I am here becuause I want to make sure the approach I am taking should be verified before I am putting hours and taking strain. A Custom (could ...

Registering for timer elapsed events

I want to create a class that initializes a timer which will be used as a central core for other class members to register themselves for the timer elapsed event. My problem is that I don't really know how to expose the timer elapsed event to other classes. One solution, that I think might work is that I simply expose the timer as a publ...

Implicit conversion to Func

Let's say I have an interface IMyInterface<T> that simply describes one function: public interface IMyInterface<T> { T MyFunction(T item); } I could just about replace this with Func<T, T>, but I want the interface for semantic reasons. Can I define an implicit conversion between that interface and Func<T,T> such that I could pas...

Why are Objective-C delegates usually given the property assign instead of retain?

Hi all, I'm surfing through the wonderful blog maintained by Scott Stevenson, and I'm trying to understand a fundamental Objective-C concept of assigning delegates the 'assign' property vs 'retain'. Note, the both are the same in a garbage collected environment. I'm mostly concerned with a non-GC based environment (eg: iPhone). Directl...

how to use variables inside a delegate function

I'm using a SDK for a usb camera. The SDK specifies that for each frame grabbed, a callback function will be called. The callback function is defined inside the SDK, it gets a data pointer to the image and a structure used to interpret the data. All of that works correctly. To make a useful application out of that, I need to access a f...

What is the difference between calling a delegate directly, using DynamicInvoke, and using DynamicInvokeImpl?

The docs for both DynamicInvoke and DynamicInvokeImpl say: Dynamically invokes (late-bound) the method represented by the current delegate. I notice that DynamicInvoke and DynamicInvokeImpl take an array of objects instead of a specific list of arguments (which is the late-bound part I'm guessing). But is that the only differe...

C# pattern to prevent an event handler hooked twice

Duplicate of: How to ensure an event is only subscribed to once and Has an event handler already been added? I have a singleton that provides some service and my classes hook into some events on it, sometimes a class is hooking twice to the event and then gets called twice. I'm looking for a classical way to prevent this from happening....

C#:: When to use events or a collection of objects derived from an event handling Interface?

I have what I think is a simple "problem" to which I have found a couple of solutions but I am not sure which way to go andn the best practice in C#. I have a master object (say a singleton) instanciated once during the lifespan of the application. This "MasterClass" creates a bunch of new type of objects, say "SlaveClass" every time Ma...

C# Get Delegate (Func) implementation from concrete class via reflection?

Hi, Sorry for the poor explaination of the problem Totally rewriting question I have the following method: public TReturn FindCached<TSearch, TReturn>(Func<TSearch, TReturn> searchMethod) where TSearch : ISearchSpecification where TReturn : class { SearchSpecification spec = new GetConcre...

Howto emit a delegate or lambda expression

Hello, I want to emit a method that returns a Func<>. Inside this method I have to create a delegate or a lambda expression which exactly serves the return type. Altogether it should look like this: // I have a resolve method that will be called inside my missing method // This is it's signature: object Resolve( params object[] args);...

Getting a delegate from methodinfo

I have a drop down list that is populated by inspecting a classes methods and including those that match a specific signature. The problem is in taken the selected item from the list and getting the delegate to call that method in the class. The first method works, but I cannot figure out part of the second. For example, public...

Send parameter to addhandler?

I have a button in a grid that I created programmatically. The button edits some data in a table using data in a hidden column of the grid that the button is in. Normally I send a hidden field the row data using javascript onclientclick of the button then make the changes to the database using that hidden field. But there must be a way t...

Application design, separated logic, delegate or not

Delegates, would those apply here? If so, how? Code examples, as I am new to this area. Logic separation is what I am intending to implement and I think my task below would be a perfect candidate. I have read that objects should be fairly independent and not hard wired to one another. ASPX (Page) <uc1:Attachment ID="Attachment1" runat...

What's the difference between Func<T, TResult> and Converter<TInput, TOutput>?

Looking at the signatures for the Func and Converter delegates, public delegate TResult Func<T, TResult>(T arg); public delegate TOutput Converter<TInput, TOutput>(TInput input); I'm struggling to see the difference between the two. Surely, if we rename the generic type arguments, they essentially amount to the same thing? Can anyon...

How is the best way to convert Action<T> to Func<T,Tres>?

I have the functions in my class with this signatures, public static TResult Execute<TResult>(Func<T, TResult> remoteCall); public static void Execute(Action<T> remoteCall) How can I pass the same delegate in the second method to the first one? Creating method with Delegate argument is not a way, because I am loosing some exception i...

How to create a delegate to an instance method with a null target?

I've noticed that the Delegate class has a Target property, that (presumably) returns the instance the delegate method will execute on. I want to do something like this: void PossiblyExecuteDelegate(Action<int> method) { if (method.Target == null) { // delegate instance target is null // do something } ...

Whats the difference between C# delegates, Dynamic Proxy, Closures and function pointers?

What are useful definitions for the common methods of passing a method or function as data, such as: Delegates Closures Function pointers Invocation by dynamic proxy and First class methods? ...

C# - How do I Pass a delegate into another method?

I'm writing a class for managing my threading. How do I pass my method that needs threading into my helper class? All that I'll be doing is creating a new thread and passing the method I've passed through into a new ThreadStart(). Thanks in advance. ...

Why would adding delegate to AVAudioPlayer cause "_NSAutoreleaseNoPool(): Object 0x55e060 of class NSCFString autoreleased with no pool in place - just leaking"?

I have been using a class to play sounds using AVAudioPlayer. Since I want to release these sounds right after they are played, I added a delegate. That causes a "_NSAutoreleaseNoPool(): Object 0x55e060 of class NSCFString autoreleased with no pool in place - just leaking" error right after the sound completes playing, but before my -a...