delegates

VB.NET Delegate code clarification

I am trying to figure out what this piece of code does. It errors often (not in a system damaging way) but enough that it bothers me. It would be great if I could get some more information on what exactly is going on here and any suggestions on how I might be able to fix/prevent this. Code Public Shared Sub Fire(ByVal thisEvent As [Del...

Unity and delegate

Hi I'm using the Unity dependency injection framework. I have two classes, that each take the same delegate parameter in the constructor. Each class should get a different method when resolved. Can I set this up without using attributes ? If not how would you do it with attributes? ...

Why doesn't this use of implicit casts work?

I've defined a generic class "Lazy<T>", for lazy evaluation and caching of the result of a delegate Func<T>. I also define two implicit cast operators so I can create a Lazy<T> from a Func<T>s, and I can assign a Lazy<T> to a T (gets the Value of the Lazy<T>) The idea is that you can pass around a Lazy<T> in place of an instance of T, ...

Why isn't inlining a method equivalent to declaring it explicitly?

Do you have a blind spot in programming? I mean is there a common technique or language feature that you can't really get used to. Well, I have one (or probably more than one) and mine is usage of delegate. Hands up! Who else doesn't feel comfortable with delegates? Be honest! So what's a delegate? Since my courses at university int...

How to forward asynchronous events to parent classes?

I'm unsure as to what is the best approach for passing events down the line to parent classes and in need of some feedback. The example code below tries to illustrate what I want to achieve. namespace test { public delegate void TestCompletedEventHandler(object sender, TestCompletedEventArgs e); public class Manager { ...

C# Events: How to process event in a parallel manner

I have an event which I would like to have processed in a parallel manner. My idea is to make each callback be added to the ThreadPool, effectivley having each method that registered the event handled by the ThreadPool. My try-out code looks something like the following: Delegate[] delegates = myEvent.GetInvocationList(); IAsyncResult[...

Interop Assembly with delegates

I've wrote a Interop Assembly for a COM library. Everything was fine, except when I've tried to support events. This is my coClass definition: coclass NetCustomWatcher { [default] interface INetCustomWatcher; [default, source] dispinterface _INetCustomWatcherEvents; }; It's pretty simple. I read a lot of articles...

Accessing properties of object from delegate.

Hi everyone, I've been cracking my head on a prob that doesn't quite make sense. Say I have the following in my project: AppDelegate MyClassA MyClassB MyViewController In MyClassA, there is a property of type MyClassB by the name classB. MyClassB has a property of type NSMutableArray by the pointer name myArray. When in the MyViewCon...

NSURLConnection delegate gets called after caller functions control is finished

i am following code from apple examples. this code is used in a method called login and i call this method from another class ABC. My problem is this when i call the Login method it will execute the code NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if (theConnection) { received...

Map of delegates in Java

Hello. I am trying to do a very simple command line library for interactive Java programs. You start the Java program and it prompts you for commands. The syntax is: > action [object_1, [object_2, [... object_n] ... ]] for example: > addUser name "John Doe" age 42 Here action = "addUser", object_1 = "name", object_2 = "John Doe", ...

Fast C++ Delegates

I'm aware of the following approaches to C++ delegates: . Interfaces with pure virtual functions . Boost.Function . The Fastest Possible C++ Delegates . The Impossibly Fast C++ Delegates . Fast C++ Delegates . Fast C++ Delegate: Boost.Function 'drop-in' replacement and multicast Each have their pros and cons. Some are faster, some ar...

Calling Subroutines from lambda in vb.net

I find myself calling functions from lambdas frequently as the provided delegate does not match or does not have sufficient parameters. It is irritating that I cannot do lambda on subroutines. Each time I want to do this I have to wrap my subroutine in a function which returns nothing. Not pretty, but it works. Is there another way of ...

What role do delegates play in dependency injection?

In most examples of dependency injection, I see simple objects being injected, such as in the example below SecurityManager gets injected into MainApplication. However, it would seem natural to inject delegates as well, as in the example below LogHandler gets injected into MainApplication. Are delegates generally not used in dependency...

Subscribe to events within a WCF service

I have a need to do some real-time rpoerting on the functionality of a WCF service. The service is self-hosted in a windows app, and my requirement is to report "live" to the host app when certain methods are called by the client. My initial thought on the task was to publish a "NotifyNow" event in the service code, and subscribe to th...

How do you use Func<> and Action<> when designing applications?

All the examples I can find about Func<> and Action<> are simple as in the one below where you see how they technically work but I would like to see them used in examples where they solve problems that previously could not be solved or could be solved only in a more complex way, i.e. I know how they work and I can see they are terse and ...

function.createdelegate

how can i call 2 methods using function.createdelgate() lik i'm having 2 methods (method_one and method_two) Function.CreateDelegate(this,method_one); but i need to call both the methods in it... ...

[iPhone] AvAudioPlayer setting delegate to nil releases the delegate object?

@implementation MyClass -(id) init { NSString *path0 = [ [NSBundle mainBundle] pathForResource:@"myfile" ofType:@"m4a" ]; mSound = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:path0] error:NULL]; mSound.delegate = self; } -(void) release { mSound.delegate = nil; //<- this line causes MyClass r...

C#: Can I cast an explicit delegate to an Action delegate?

Given: delegate void Explicit(); Can I: public void Test(Explicit d) { Action a; a = d; // ???? } I have a scenario where I need to overload a constructor that has: public MyClass(Expression<Action> a) {} but the following overload is ambiguous: public MyClass(Action a) {} I figured using an explicit delegate would r...

didReceiveData of NSMutableUrlRequest never triggered

Hi I’m new in iphone development world and I’m trying to call a web service using the HTTP method POST. To do that I'm using the NSMutableUrlRequest. My problem is that the DidReceiveData delegate is never called and the NSUrlConnection doesn’t return null. Here is my code : - (void)connection:(NSURLConnection *)connection didRecei...

Handling Parameters in Threads

I am just a beginner."ParameterizedThreadStart" accepts single object as argument. Is there any other delegate signature allows me to (1) pass params (variable number of parameter) on thread? (2) support generic parameters like list ? ...