delegates

Using Delegates to simulate connected objects

拟墨画扇 提交于 2020-02-02 12:18:28
问题 I'm writing an application where I need to simulate the distribution of a resource such as electricity or gas among a large network of objects connected to each other in arbitrary ways. No physics need to be simulated. Just the flow of the units of resources when objects ask for them. Consider the below diagram: ObjA <---> ObjB <---> PwrA <---> ObjF /\ ObjG ObjE<---/ \---> PwrB The Pwr objects can provide resource electricity when asked by the Obj objects. What I need to simulate here is that

Understanding Lambda expressions and delegates [closed]

自闭症网瘾萝莉.ら 提交于 2020-01-30 14:36:19
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I have been trying to figure this out for quite sometime (reading online blogs and articlaes), but so far unsuccessful. What are delegates? What are Lambda Expressions? Advantages and disadvantages of both? Possible best practice of when to use one or the other? Thanks in advance.

Fill different UITextField with the same personalised keyboard

旧城冷巷雨未停 提交于 2020-01-25 08:44:25
问题 I've got a view where I've different UITextfield . To fil this TF I use a personalised UIPickerview as keyboard. My problem is, when I select the First TF the keyboard open and I can select my value. The value go to this selected TF. Now when I select the second TF the keyboard appears but the value goes to the first TF ... I don't know why this not works ... In my ViewDidLoad T've got : flightTimeSe.inputAccessoryView = Ttoolbar flightTimeSe.delegate = self flightTimeMe.inputView =

Passing data between class and form in C# using delegate parameter

谁都会走 提交于 2020-01-25 07:46:11
问题 I have to pass value into RichTextBox from a class. Here is my code. I have to pass values into any tools like textbox, listbox but I don't know how. I have to use delegates to pass md value to both methods and into the same richtextbox. namespace delegateEx2 { public class MyClass : Form1 { delegate void MyDelegate(string MyString); public void ShowThoseMessages() { MyDelegate md = new MyDelegate(log1); md += log2; md("Error Log Text"); } public void log1(string message) { //what can I write

Sending Events to a specific Thread

安稳与你 提交于 2020-01-25 05:30:27
问题 I have a situation in which I want a thread to process some sequential logic. This thread would need to interact with the main thread on occasion in order to update user input. But it should continue running otherwise without bothering the main thread. I am hopping to do this in an event-driven manner, so that the main thread doesn't have to pole the other thread for interrupts. What is the best way to do this? Is there an event-driven technique to communicating between threads much like

Sending Events to a specific Thread

回眸只為那壹抹淺笑 提交于 2020-01-25 05:30:25
问题 I have a situation in which I want a thread to process some sequential logic. This thread would need to interact with the main thread on occasion in order to update user input. But it should continue running otherwise without bothering the main thread. I am hopping to do this in an event-driven manner, so that the main thread doesn't have to pole the other thread for interrupts. What is the best way to do this? Is there an event-driven technique to communicating between threads much like

2 UITableView in a UIViewController affecting each other

放肆的年华 提交于 2020-01-24 20:42:10
问题 I've been going at this for about 3 hours now, and I'm finally throwing in the towel to y'all. I have 2 UITableView in my view, one of which is a forum board to leave comments and what not, and the second UITableView is used to mention people. the issue I am having is that both tableview counts are being affected even if i only want to update just 1 of the tableviews. I set the delegate/datasource in the viewdidload self.mentionTableView.delegate = self; self.mentionTableView.dataSource =

Get the result of Func<object> when object is a Task<Something>

谁说胖子不能爱 提交于 2020-01-24 10:11:46
问题 I am currently using this code to attempt to dynamically execute a saved Func<object> : public async Task<object> GetFuncResult(string funcName) { Func<object> func = _savedFuncs[funcName]; bool isAwaitable = func.Method.ReturnType.GetMethod(nameof(Task.GetAwaiter)) != null; if (!isAwaitable) return func(); else return await ((Func<Task<object>>)func)(); } If somebody stores a Func<Task<object>> or a Func<[anything]> this code works fine. But if somebody stores a Func<Task<string>> (or any

C# Elasticsearch NEST cannot convert lambda expression

柔情痞子 提交于 2020-01-24 05:38:25
问题 I'm running into exactly the same problem described (and not answered) here ElasticSearch NEST Search I use: .NET Framework 4.5; ASP.NET MVC 5; Elasticsearch 1.6.0 (on a server); Elasticsearch.NET 1.6.1 NEST 1.6.1 I have an MVC controller which has two actions: Index - which contains HTML UI form Search - which contains Elasticsearch.NET client and a query. public ActionResult Search(SearchCreteria sc) { Settings settings = new Settings(); Client client = new Client(settings);

Write C# delegate in java

送分小仙女□ 提交于 2020-01-23 19:08:00
问题 How can I write code below in java version? I have read similar questions, but they are confusing, they answered that java didn't have delegate feature like c# had, in other hand they answered with their delegate implementation in java, but nothing is similar with my condition. I really hope it's clear on this question. I have been getting stuck since a week class Action { public delegate void ActionDelegate(); public static ActionDelegate OnAction; public void DoAction() { Console.WriteLine(