anonymous-methods

event handler for WebBrowser control onpropertychange events - sender and e objects are null

旧城冷巷雨未停 提交于 2021-02-16 20:26:11
问题 In C#, I am running the WebBrowser (WB) control in a server-side thread and want to monitor (listen) for "onpropertychange" events. I can successfully attach a .NET delegate signature method that is executed when a property changes, but the sender and e objects are both null in every call to qEventHndlr, therefore, I don't know which property changed to fire the event. el is an HTMLElement that is iterated in a foreach loop to attach the eventhandler to each element to monitor (listen). el

event handler for WebBrowser control onpropertychange events - sender and e objects are null

故事扮演 提交于 2021-02-16 20:26:06
问题 In C#, I am running the WebBrowser (WB) control in a server-side thread and want to monitor (listen) for "onpropertychange" events. I can successfully attach a .NET delegate signature method that is executed when a property changes, but the sender and e objects are both null in every call to qEventHndlr, therefore, I don't know which property changed to fire the event. el is an HTMLElement that is iterated in a foreach loop to attach the eventhandler to each element to monitor (listen). el

How to assign a function, returned by another function, to a function variable? The result rather than the generating function itself

て烟熏妆下的殇ゞ 提交于 2021-02-07 11:22:05
问题 A function is returning an anonymous function. I would like to assign the result to a variable. However the compiler thinks that I am trying to assign the function and not the result of the function. How can I resolve this? program Project9; {$APPTYPE CONSOLE} type TMyEvent = reference to function: string; var v1: TMyEvent; function GetHandler: TMyEvent; begin Result := function: string begin Result := ''; end; end; begin v1 := GetHandler; // <- Incompatible types: 'TMyEvent' and 'Procedure'

How can I capture variables by anonymous method when using it in OTL?

二次信任 提交于 2020-03-16 05:22:40
问题 What I want to do: I have a few objects in a genric list. I want to capture each of this object in anonymous method and execute this method as a separate OTL Task. This is a simplified example: program Project51; {$APPTYPE CONSOLE} uses SysUtils, Generics.Collections, OtlTaskControl, OtlTask; type TProc = reference to procedure; type TMyObject = class(TObject) public ID: Integer; constructor Create(AID: Integer); end; constructor TMyObject.Create(AID: Integer); begin ID := AID; end; var

Why Local Functions generate IL different from Anonymous Methods and Lambda Expressions?

╄→尐↘猪︶ㄣ 提交于 2020-01-22 17:36:06
问题 Why the C# 7 Compiler turns Local Functions into methods within the same class where their parent function is. While for Anonymous Methods (and Lambda Expressions) the compiler generates a nested class for each parent function, that will contain all of its Anonymous Methods as instance methods ? For example, C# code (Anonymous Method) : internal class AnonymousMethod_Example { public void MyFunc(string[] args) { var x = 5; Action act = delegate () { Console.WriteLine(x); }; act(); } } Will

DataTable.Select vs DataTable.rows.Find vs foreach vs Find(Predicate<T>)/Lambda

懵懂的女人 提交于 2020-01-10 07:58:29
问题 I have a DataTable/collection that is cached in memory, I want to use this as a source to generate results for an auto complete textbox (using AJAX of course). I am evaluating various options to fetch the data quickly. The number of items in the collection/rows in the datatable could vary from 10000 to 2,000,000. (So that we dont get diverted, for the moment assume that the decision has been made, I have ample RAM and I will be using the cache and not database query for this) I have some

Update ref parameter inside anonymous method

*爱你&永不变心* 提交于 2020-01-03 08:44:08
问题 Is there a workaround to update a ref parameter inside an anonymous method? I know that the an anonymous method doesn't allow access to ref parameters of the outer scope, but is there another way to do it? I am using an external library for the MessageStream so cannot alter the arguments of the delegate... void DoWork(ref int count) { MessageStream Stream = new MessageStream(); Stream.MessageReceived += (o, args) => { //Error cannot use ref or out parameter inside anonymous method count++; };

Is there a case where delegate syntax is preferred over lambda expression for anonymous methods?

拜拜、爱过 提交于 2020-01-01 02:17:50
问题 With the advent of new features like lambda expressions (inline code), does it mean we dont have to use delegates or anonymous methods anymore? In almost all the samples I have seen, it is for rewriting using the new syntax. Any place where we still have to use delegates and lambda expressions won't work? 回答1: Yes there are places where directly using anonymous delegates and lambda expressions won't work. If a method takes an untyped Delegate then the compiler doesn't know what to resolve the

Are anonymous listeners incompatible with weak references?

天涯浪子 提交于 2020-01-01 02:08:33
问题 I was reading this question that just got asked: Avoid memory leaks in callbacks? And I was quite confused, until someone answered the following: "The problem with this approach is you cannot have a listener which is only referenced in the collection as it will disappear randomly (on the next GC)" Am I correct in my understanding that using a weak references, like when stored in a WeakHashMap , is incompatible with anonymous listeners? I typically pass listeners like this: public static void