delegates

How to Get Function String Assigned to Delegate

Hi Everyone, As you may know, when we have this code in Javascript : function getName() { var getName = "Hello"; return getName; } var NameString = getName; alert(NameString.toString()); will return ; function getName() { var getName = "Hello"; return getName; } as string rather than the result of the function invocation...

Create a delegate of a generic function

I'm writing some unit tests and I have a lot of functions of the form public void SomeTestHelperMethod<TKey, TValue>(TKey key, TValue value) which I'm calling repeatedly with various arguments like this SomeTestHelperMethod<int, int>(0, 1); SomeTestHelperMethod<int, object>(1, new Nullable<double>(16.5)); SomeTestHelperMethod<int, st...

Passing Delegate object to method with Func<> parameter.

I have a method Foo4 that accepts a parameter of the type Func<>. If I pass a parameter of anonymous type , I get no error. But if I create and pass an object of the type 'delegate' that references to a Method with correct signature, I get compiler error. I am not able to understand why I am getting error in this case. class Learn6 ...

In C# could we imagine writing our own events without writing delegates?

I learned the object-oriented in Java. Now in develop in C#. This means that I never really understood the functioning of delagates but I know how to use them. Lately I discovered this page http://java.sun.com/docs/white/delegates.html. If Java is able to create event without delagates is it possible to do the same in C#? Could we imag...

Why are delegates null rather than an empty list when there is no subscriber?

Can somebody explain why the .Net framework team decided that a delegate without subscribers should be null instead of an object with an empty InvocationList? I'd like to know the rationale that led to this decision. void DoSomething() { EventHandler handler = SomeEvent; if(handler != null) //why is this null-c...

Problem with delegates in C#

In the following program, DummyMethod always print 5. But if we use the commented code instead, we get different values (i.e. 1, 2, 3, 4). Can anybody please explain why this is happenning? delegate int Methodx(object obj); static int DummyMethod(int i) { Console.WriteLine("In DummyMethod method i = ...

Simple Delegate. what's wrong is my code?

class SimpleDelegate { public delegate void LogHandler(string message); public void Process(LogHandler logHandler) { if (logHandler != null) { Console.WriteLine("Process begin"); } if (logHandler != null) { Console.Wr...

NSOperation will not cancel NSXMLParser. Which continues to call methods on delegate causing crash

I am trying to download some XML on another thread, and parse it. I release the 'controller' then call cancelAllOperations on the NSOperationQueue. And implement method 'cancel' on NSoperation which attempts to set nSXMLParser's delegate to nil. But a second or so later the NSXMLParser is still alive and kicking and calls methods on i...

Present Navigation Table View modally, who is the delegate?

Basically I have a hierarchy of locations: country, state/prov, city. I want to present an "Add Location" modal table using a delegate. I realize the best way to do this is to present my top level elements in a TableView, and if they are selected, I want to go down to the 'next' level. Any of the locations however, on any level should...

merging or combining two projects. two delegates, two windows.

Thinking about divide and conquer, I decided to start an application having small pieces of my big app. I thought it was more convenient and easier specially as far as errors go. When I tried to merge two of them, I faced the problem of having separate delegates, and mainwindow. Maybe merging the method of the delegate applicationDidFini...

Merge iPhone app delegate into another project

I have an open-source iPhone API that I downloaded, and that is a standalone app with its own app delegate and applicationDidFinishLaunching: method. How do I merge this into my own app, and keep all the methods in the app delegate? ...

Delegates And WCF Methods

Hi. I have successfully designed a large file upload method using WCF. Now, I would like to report progress for each unique file being loaded. In my upload method, i have the following code block: while ((bytesRead = request.FileByteStream.Read(buffer, 0, bufferSize)) > 0) { outfile.Write(buffer, 0, bytesRead); totalBytesRea...

Asynchronous runtime method invocation

I am loading some assemblies at run time and invoking methods on them using Reflections (MethodInfo.Invoke). Now I want to make these calls asynchronous. So I am thinking of using Delegate.BeginInvoke(). But I am not sure how to create delegate instance by providing function name at run-time. (All examples I see have delegate instance t...

delegate parameter from another class

Hi: In c or c++ we can use function pointer as a parameter to another function like this: int example(FUNPTR a) { /* call the function inside */ a(); } And I also know that we can use delegates in c# as function pointer, but what if the method I want to assign to the delegate exists in another class, does that mean both class nee...

iPhone: Get Response From Finished Request [ASIHttpRequest]

Hello all. I am attempting to use ASIHttpRequest with the iPhone to get some information from a query-string based API on my site. Currently, I am in the planning stages of my design and I am kind of stuck on how I should proceed. I would like to have a class, that will handle all of the requests I will need. I plan on having differe...

How to know when a UserControl has finished firing an Event?

we have a UserControl to handle User cancellations, that is used in a few places. This has a couple of input fields and a submission button. When they submit the User's status is updated and a few other things are done and a feedback message displayed. On one of the pages which includes the control, after the User has successfully cance...

What is the difference between a delegate instance and a method pointer?

I thought that a delegate instance was interchangeable with a function instance. Take the following code: delegate int AddDelegate(int a, int b); AddDelegate DelegateInstance; public void DoStuff() { //I can call this without a delegate "instance": MethodThatTakesAdd(Add); //I can also call it WITH a delegate "instance" ...

invoking delegate with generics arguments in c#

I have a class: public class MyClass<T> { public string TestProperty { get; set; } } and I want to create a delegate to run on instances of this class, such as: Action<MyClass<object>> myDelegate = myclass => myclass.TestProperty = "hello"; However, the above delegate can't be invoked with anything other than a MyClass<object>,...

C# Custom Events with Overloads

So I have a custom event like this: Work w = new worker() w.newStatus += new worker.status(addStatus); w.doWork(); void addStatus(string status) { MessageBox.Show(status); } and this: public event status newStatus; public delegate void status(string status); public void doWork() { ...

How can i do this with the C# 'new Process' object.

Hi folks, I wish to pass some data to the delegate method, of a Process object, when it fires the Exited event --- i'm not sure how. I've got some code (in a windows service) that is going to take a while .. so i'm forking off a new process to do it .. like ... string recipientEmail = "[email protected]"; var commandProcess = new P...