How to create an asynchronous method

You need to use delegates and the BeginInvoke method that they contain to run another method asynchronously. A the end of the method being run by the delegate, you can notify the user. For example: class MyClass { private delegate void SomeFunctionDelegate(int param1, bool param2); private SomeFunctionDelegate sfd; public MyClass() { sfd = new SomeFunctionDelegate(this.SomeFunction); … Read more

How to use custom delegates in Objective-C

You will want to declare a delegate protocol for your class. An example of a delegate protocol and interface for class Foo might look like this: @class Foo; @protocol FooDelegate <NSObject> @optional – (BOOL)foo:(Foo *)foo willDoSomethingAnimated:(BOOL)flag; – (void)foo:(Foo *)foo didDoSomethingAnimated:(BOOL)flag; @end @interface Foo : NSObject { NSString *bar; id <FooDelegate> delegate; } @property (nonatomic, retain) … Read more

Cannot convert from ‘method group’ to ‘System.Action’ error

DelegatedCall expects a delegate that takes any object as an argument. But your function foo1 that you are passing to DelegatedCall can only cope with a string argument. So, the conversion isn’t type-safe and thus is not possible. Input parameters are contra-variant, but your code needs covariance. (See Difference between Covariance & Contra-variance.) You can … Read more

Why are there memory allocations when calling a func

You’re using a method group conversion to create the Func<long, long, bool> used for the comparerFunc parameter. Unfortunately, the C# 5 specification currently requires that to create a new delegate instance each time it’s run. From the C# 5 specification section 6.6, describing the run-time evaluation of a method group conversion: A new instance of … Read more

Is it possible to have a delegate as attribute parameter?

No, you cannot have a delegate as an attribute constructor parameter. See available types: Attribute parameter types As a workaround (although it’s hacky and error prone) you can create a delegate with reflection: [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false, Inherited = true)] public class WorkspaceAttribute : Attribute { public ConnectionPropertiesDelegate ConnectionDelegate { get; set; } … Read more

Is EndInvoke() optional, sort-of optional, or definitely not optional?

Delegate.EndInvoke is documented as a thou shalt call this (i.e. necessary – else leaks happen) – from msdn: Important Note No matter which technique you use, always call EndInvoke to complete your asynchronous call. Control.EndInvoke is OK to ignore for fire-and-forget methods – from msdn: You can call EndInvoke to retrieve the return value from … Read more

Delegates, Why? [duplicate]

Changing functionality at runtime is not what delegates accomplish. Basically, delegates save you a crapload of typing. For instance: class Person { public string Name { get; } public int Age { get; } public double Height { get; } public double Weight { get; } } IEnumerable<Person> people = GetPeople(); var orderedByName = people.OrderBy(p … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)