delegates

Error binding to target method in C#3.0

心已入冬 提交于 2019-12-24 07:55:45
问题 I am trying to hook Up a Delegate Using Reflection. This is what I have done so far using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.Data; using System.Threading; using System.IO; using System.Reflection; using System.Windows; namespace ChartHelper { public class ICChartHelper { public void RefreshChart() { try { Assembly myobj = Assembly.LoadFrom(@"C:\sample.dll"); foreach (Type mytype in myobj.GetTypes()) { if (mytype

Nonblocking update to a DataGridView

♀尐吖头ヾ 提交于 2019-12-24 07:07:03
问题 I understand how to use delegates to update controls on the main control thread, works like a charm. My problem here is if I'm adding a large DataSet (say 2000 items) to a bound DataGridView , it takes 5-8 seconds for the grid to populate and during that 5-8 seconds the whole GUI is locked. How can I update the DataGridView such that it doesn't lock the user interface? To be clear, the problem isn't that I'm doing a slow query to a database and the UI is blocking on that, I already have the

Using delegates with non static methods [no picked answer]

南笙酒味 提交于 2019-12-24 06:26:18
问题 I am pretty confident that I should be able to use a delegate with a non-static method, but the below is giving me an error: public class TestClass { private delegate void TestDelegate(); TestDelegate testDelegate = new TestDelegate(MyMethod); private void MyMethod() { Console.WriteLine("Foobar"); } } The error I am getting is: A field initializer cannot reference the non-static field, method, or property If I make MyMethod static, everything works fine. Was I simply wrong in thinking I could

Making a return inside callback

╄→гoц情女王★ 提交于 2019-12-24 06:03:29
问题 public static string GetFoo() { string source = GameInfoUtil.GetSource(repairRequest, () => { return "0"; // this line gives error }); . . MORE WORK, BUT WANT TO SKIP IT } public static string GetSource(WebRequest request, Action failureCallback) { // DOING WORK HERE WITH REQUEST if(WORK IS SUCCESSFULL) RETURN CORRECT STRING ELSE CALL -> failureCallback(); return ""; } I want to do smthing like this, but it gives me error: Error 2 Cannot convert lambda expression to delegate type 'System

Using TableView as ListView-delegate

馋奶兔 提交于 2019-12-24 04:32:35
问题 I have a model that contains several QStandardItemModels . Now I want to create a view that displays a TableView for each QStandardItemModel . I had the idea to have a ListView that has a TableView as delegate, something like this: ListView { id: myListView anchors { fill: parent margins: 5 } model: testModel delegate: CompareDelegate { } } And in CompareDelegate.qml : Item { id: base width: 500 height: 300 TableView { anchors.fill: parent } } How do I get the TableView inside the delegate to

Present “Controller” from another Class in Objective-C

泄露秘密 提交于 2019-12-24 03:29:51
问题 How does one present a UIAlertController from another class? I want to know how can you capture the action of an "ok" button in a UIAlertController that was created in Class B but presented in Class A. This is how I call the method that created the Alert on class "ErrorHandler" from ClassA: ErrorHandler *handler = [[ErrorHandler alloc] init]; [self presentViewController:[handler alertWithInternetErrorCode] animated:YES completion:nil]; And this is the implementation of

Weird example of variance rules for delegates

一曲冷凌霜 提交于 2019-12-24 03:26:39
问题 In Eric Lippert's blog posts about covariance and contravariance or variance for short, and in books such as C# in a Nutshell , it is stated that : If you’re defining a generic delegate type, it’s good practice to: Mark a type parameter used only on the return value as covariant (out). Mark any type parameters used only on parameters as contravariant (in). Doing so allows conversions to work naturally by respecting inheritance relationships between types. So I was experimenting this and I

Creating a Messenger service

不打扰是莪最后的温柔 提交于 2019-12-24 03:05:16
问题 To help reduce dependencies between my ViewModels, I am trying to create my own Messenger service. Here is some code: public struct Subscription { public Type Type { get; set; } public string Message { get; set; } //Error: Cannot implicitly convert type 'System.Action<TPayload>' to 'System.Action' public Action Callback { get; set; } } public static class Messenger { private static List<Subscription> Subscribers { get; set; } static Messenger() { Subscribers = new List<Subscription>(); }

Can you use .net 3.5 Action or Func as Marshalled unmanaged delegates?

こ雲淡風輕ζ 提交于 2019-12-24 03:03:58
问题 After reading Dynamically calling unmanaged dlls in .net I've been trying to modify the code to my liking. I made a class that implements idisposable to wrap load calls in and free them when needed. However I can't seem to figure out the syntax if it is possible to use anonymous delegates with it. var loaded=DynamicLibraryLoader.TryLoad("User32.dll"); var beeper=loaded.GetProcAddress("MessageBeep"); var type=typeof(Action<UInt32>); Action<UInt32> beepAction2=(Action<UInt32>) Marshal

How Do I Use a QStyledItemDelegate to Paint Only the Background, Without Covering the Text?

时间秒杀一切 提交于 2019-12-24 02:52:16
问题 How should I change just the background color of my tree item using a delegate? I haven't been able to figure out how to do this without painting on top of the text. In other words, when I use the code below, the color is drawn on top of the text. The text is under the background... def paint(self, painter, option, index): MyDelegate.paint(self, painter, option, index) painter.save() # set background color painter.setPen(QPen(Qt.NoPen)) if self.item.is_set and option.state & QStyle.State