delegates

Understanding multithreading, delegates and static

Okay, I'm trying to write a program that will scan a bunch of words to match against a set of letters. I want all words displayed that contain the letters entered by the user and I want these words displayed while the program is still searching. Therefore, I have to split the search onto its own thread, separate from the UI thread. Ea...

What is meant by delegates in C++?

What is mean by delegates in c++, does sort function in c/c++ which takes a compare function/functor as last parameter is a form of delegate? ...

Why is this blocking? (VB.NET multithreading with events and delegates)

Hello all I have a feature whereby a class in a dll displays a form asking a user to clear a fault on a printer before clicking a button to say "Retry". The users have been just hitting retry without bothering to clear the fault so I am now coding an interlock: The button on the invoked form is disabled until a call is made to an 'enab...

Asp.net: Can a delegate ("Action") be serialized into control state?

I am implementing a user control that has a method that takes an Action delegate as a parm. Attempting to store the delegate in Control State yields a serialization error. Is it even possible to serialize a delegate into Control State? BP ...

C# List<T>.ConvertAll in .NET 2.0

I have a list of strings. All of the strings have whitespace that needs to be converted to underscores. I am fully capable of using a for or foreach loop to do this. I am still relatively new to C# and would like to become more familiar with it. With that said, my question is: How can I get the following code to work in .NET 2.0? When I...

Can I set a Func<> function with runtime variables to omit passing them as parameters in C#?

Hello, I have a numerical analysis program which for simplicity calculates an algorithm similar to: y = ax^3 + bx^2 + cx + d; I calculate the values of a,b,c,d at runtime and would like to pass the following equivalent as a Func<double, double>. Where I can set a value for X, and get Y. y = 12x^3 + 13x^2 + 14x + 15; Where 12,13,14...

C# new [delegate] not necessary?

I've been playing with HttpWebRequests lately, and in the tutorials they always do: IAsyncResult result = request.BeginGetResponse( new AsyncCallback(UpdateItem),state); But new AsyncCallback doesn't seem to be necesary. If UpdateItem has the right signature, then there doesn't seem to be a problem. So why do people include it? Does...

[C#] Delegate Calling in a Constructor

I've run into an easily solved but a design problem I've not encountered in my young life yet. I have a class that needs to go through a few setup procedures before anything else happens. However, during the construction of this class, I have in the constructor's parameters a delegate that can be passed so that the user can add their o...

Why doesn't Java have method delegates?

The Java gurunaths (natha नाथ = sanskrit for deity-master-protector) at Sun should condescend to accept the necessity of delegates and draft it into Java spec. In C#, I can pass a method as a handler referenced as a delegate, without needing to go thro the trouble of creating a class just because I need to pass a method in Java. What a...

Why don't anonymous delegates/lambdas infer types on out/ref parameters?

Several C# questions on StackOverflow ask how to make anonymous delegates/lambdas with out or ref parameters. See, for example: Calling a method with ref or out parameters from an anonymous method Write a lambda or anonymous function that accepts an out parameter To do so, you just need to specify the type of the parameter, as in: p...

abstracting code from two methods in Java, maybe use delegates?

I have two methods that do essentially the same thing, just with different types. I want to abstract out this functionality to some generic method and I think I could do it easily in C# with delegates, but I don't know the equivalent in Java. I'm just showing two of the methods here, but there are several (like eight) different makeWha...

Passing a Delegate as Callback to a Native C++ API Call

Could someone point me whats wrong with this code please? I'm having a very hard experience in mixing C++ and MC++. I have read a lot of blogs and tutorial regarding this subject (passing delegates) but now that looks my code is ok (its compiling and runs well when in debug mode and step by step) it crashs. The main problem is that it n...

Suggestions needed for architecting my code.

Background I'm writing an part of my app that has no UI. It sits in the background watching what you do and timing your work. There should be no overlapping times, and there should be no breaks in the time data. If there are either of these things, the app has a bug somewhere and I need to be notified. What I Want A class called JG...

Storing a Method as a Member Variable of a Class in C#

Hi, I have this as one of my members of the class 'KeyEvent': private delegate void eventmethod(); And the constructor: public KeyEvent(eventmethod D) { D(); } What I want to do is instead of calling D() there, I want to store that method (D) as a member variable of KeyEvent, so something like: stored_method = D();...

Pass and execute delegate in separate AppDomain

I want to exceute some piece of code in separate AppDomain with delegate. How can I do this? UPD1: some more details about my problem My program processing some data (one iteration is: get some data from DB, evaluate it and create assemblies at runtime, execute dynamic assemblies and write results to DB). Current solution: each iterat...

C# how can a delegate & interface method interchangable

Can I use interface method instead of delegate? How? I found searching that interface method is faster than using delegates. I would appreciate a simple code snippet. ...

Using delegates with arguments...

I have a class 'KeyEvent'; one of which's members is: public delegate void eventmethod(object[] args); And the method passed to the object in the constructor is stored in this member: private eventmethod em; Constructor: public KeyEvent(eventmethod D) { em = D; } public KeyEvent(eventmethod D, object[] args) : this(D) { ...

when & why to use delegates?

Hi everyone, I'm relatively new in c#, & I'm wondering when to use Delegates appropriately. they are widely used in events declaration , but when should I use them in my own code and why are they useful?, why not to use something else? I'm also wondering when I have to use delegates and I have no other alternative. Thx for the help. ...

Problem with event "chaining"

Note: I edited this question to make it easier for other people with the same problem to get help here. To see the original question that fits better with some of the answers, check the edit history. In a project I have a ExecutionManager class that can contain multiple ExecutionSlot's instances. The ExecutionSlot class have several pub...

iPhone - switching a view controller in the tabbar and call a method

Hello! I have a TabBar in my application and I do this in my AppDelegate: ... test2ViewController = [[Test1ViewController alloc] init]; ... navigationTest2Controller = [[UINavigationController alloc] initWithRootViewController:test2ViewController]; NSArray *myControllers = [NSArray arrayWithObjects:..., navigationTest2Controller, nil]...