delegates

Best way to get object data?

Hey guys, I need to display some stats, numbers, and graphs about various game objects on the screen. (examples: camera position, field of view, frames per second, fill rate, number of objects culled, etc... ) Currently any object which wants to be graphed or displayed implements an interface along these lines: public interface IGra...

Lambda expression - How to work on delegates in CSharp ?

I took the following example from Jrista's answer to a post. Finding Twentyone count int[] numbers = new[] { 1, 3, 11, 21, 9, 23, 7, 4, 18, 7, 7, 3, 21 }; var twentyoneCount = numbers.Where(n => n == 21).Count(); Suppose i use "Func" delegate how can i get the count ? I tried as (pardon me for the bad syntax) var otherway= F...

A general delegate type for handling any event.

Hey, I have a function that receives two parameters - an object, and an EventInfo structure defining an event on that object. I need to block that function until the specified event fires. The problem I have is, how do I add a delegate to the specified event, when the type of handler could be anything? Note that I don't care about the ...

Convert C# statement body lambda to VB

It appears that VB in VS8 doesn't support/convert lambda expressions with a statement body. I'm using them in my C# application, but now must convert it to VB. I'm creating a whole bunch of controls dynamically, and I want to be able to give them event handlers on the fly. This is so I can build a dynamic user interface from a databas...

Why does marshalling a struct of callback delegates cause an AccessViolationException

Introduction I am trying to use P/Invoke to register a struct of callbacks with a native dll. When calling a function that makes the native dll invoke the callbacks an AccessViolationException occurs. I have constructed a "small" test case that demonstrates the behavior comprised of 2 files, native.cpp that compiles into native.dll and ...

Events/Delegates In Java or C#

I've been trying to learn about events/delegates, but am confused about the relationship between the two. I know that delegates allow you to invoke different functions without needing to know what particular function is being invoked. (eg: a graphing function needs to accept inputs that are different functions to be graphed). But I don...

C# print a delegate

Is there a simple way to print the code of a delegate at runtime ? (that "contains one method"). public delegate void SimpleDelegate(); SimpleDelegate delegateInstance = delegate { DoSomeStuff(); int i = DoOtherStuff() }; Now, I would like to display on the screen the body of delegateInstance. That is to say, doing someth...

Comparison Delegate flip flops results on identical keys

Is there any way to get consistent results from Comparison when some of the sort items are the same? Do I just have to code up my own sort routine? public class Sorter { public void SortIt() { var myData = new List<SortData>(3); myData.Add(new SortData { SortBy = 1, Data = "D1"}); myData.Add(new So...

How to execute a callback method instead of an anonymous method?

The following example works, but how can I change it so that instead of executing the anonymous method, it executes my existing callback method OnCreateOfferComplete()? using System; namespace TestCallBack89393 { class Program { static void Main(string[] args) { OfferManager offerManager = new OfferM...

Is this delegate usage good or bad?

This question is being asked because I have no prior experience with delegate best practices I have a unordered lists in html, where the structure is the same throughout my site, but the content of the lists may differ. Examples: List of object A <ul> <li> <ul> <li>A.someMember1</li> <li>A.someMember2</li> <li>...

How to make Action<param,param2> compatible with event's delegate type?

Given the code below: void LookupBox_Load(object sender, EventArgs e) { Action d = delegate { if (!_p.AutoClose) CloseLookupBox(); }; if (this.ParentForm.MdiParent != null) this.ParentForm.MdiParent.Deactivate += delegate { d(); }; else this.ParentForm.Deactivate +...

When does the vaIue of the InvokeRequired property change?

When i want to use delegate class to make call while windows form working, i always have to use InvokeRequired. It is ok. But who changed the InvokeReuqired property while it is working. Please check this image: ...

How can I get delegates to property accessors from a generic type?

I'm currently building a node editor (as in Blender) and am having trouble getting delegates to property accessors from a generic type. So far the question here has brought me closest, but I'm having trouble that I think is specifically related to the type of object being generic. For reference, a "Node" is synonymous with an object, an...

Does using a delegate create garbage

I'm working on a game for the xbox360, using XNA. On the Xbox the garbage collector performs rather badly compared to the one on a PC, so keeping garbage generated to a minimum is vital for a smoothly performing game. I remember reading once that calling a delegate creates garbage, but now for the life of me can't find any references to...

C# OnPropertyChangedEvents Implementation and Delegate Question

I have a progress bar on a UI I would like to update when a record gets inserted into my database. I have done this before when I only had a UI Tier and a Business Tier with no problems. But I am now breaking my code into a UI Tier, Business Tier, and Data Tier and I can't figure how to properly call my OnPropertyChangedEvent in my Dat...

Cast between function pointers

Hello, I am currently implementing a timer/callback system using Don Clugston's fastdelegates. (see http://www.codeproject.com/KB/cpp/FastDelegate.aspx) Here is the starting code: struct TimerContext { }; void free_func( TimerContext* ) { } struct Foo { void member_func( TimerContext* ) { } }; Foo f; MulticastDelegate< ...

ASP.NET Delegates and Expressions -Information Request

Based on my understanding , i interpret the meaning of Func delegate as follows.Please correct them as and when it is needed. Declaration : Func<int> dg ; 1. Could i interpret it as "a Delegate pointing to a method that returns an integer?". Declaration : Func<int,int> delg1=r=>2*r; *2. Could i interpret it as " 'r' is a la...

Use reflection stub to initialize a delegate field lazily

The problem: a .Net 2.0 class with a few thousand delegate fields generated by a code generator varying signatures delegates may or may not return values no generics these delegates much be initialized quickly at runtime initializing a delegate is simple but expensive initializing the whole lot costs ~300ms right now - acceptable,...

Question about foreach and delegates

Suppose the following code: foreach(Item i on ItemCollection) { Something s = new Something(); s.EventX += delegate { ProcessItem(i); }; SomethingCollection.Add(s); } Of course, this is wrong because all the delegates points to the same Item. The alternative is: foreach(Item i on ItemCollection) { Item tmpItem = i; Som...

a constructor as a delegate - is it possible in C#?

I have a class like below: class Foo { public Foo(int x) { ... } } and I need to pass to a certain method a delegate like this: delegate Foo FooGenerator(int x); Is it possible to pass the constructor directly as a FooGenerator value, without having to type: delegate(int x) { return new Foo(x); } ? EDIT: For my personal use, ...