delegates

Scala delegate import of implicit conversions

纵饮孤独 提交于 2019-12-22 10:00:00
问题 In Scala, how can I delegate the importing of implicit conversions into my scope, such that I don't have to have a big "environment" class which provides both library functions/values (for a DSL I am creating) as well as implicit conversions? In short, can I move my implicit conversions from an object, and still have it imported when I write: import MyDslEnvironment._ ? The goal of this is to make the importing and use of my framework simple and lightweight, in the sense that only a single

How to Changing ListView inside backgroundworker? Cross-Thread Error [duplicate]

与世无争的帅哥 提交于 2019-12-22 09:40:19
问题 This question already has an answer here : Closed 6 years ago . Possible Duplicate: Most concise and proper way of avoiding cross thread operation error? I got error when running my programs.... {"Cross-thread operation not valid: Control 'listView1' accessed from a thread other than the thread it was created on."} private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { TestObject argumentTest = e.Argument as TestObject; string[] lines = argumentTest.ThreeValue.Split(new

iPhone: How to Close MFMailComposeViewController?

安稳与你 提交于 2019-12-22 09:13:07
问题 I'm having difficulties closing an email message that I have raised. The email opens nicely, but once it is opened it will not close as the mailComposeController:mailer didFinishWithResult:result error:error handler never gets invoked. As far as I can tell I have all the bits in place to be able to do this. Anyone any ideas of what I can look at? Here is how I raise the email: -(IBAction)emailButtonPressed { NSString *text = @"My Email Text"; MFMailComposeViewController *mailer = [

CreateDelegate instead of Reflection for SetValue

本小妞迷上赌 提交于 2019-12-22 09:00:01
问题 I tried to implement Jon Skeet's solution for this question posted on this blog post to substitute the SetValue method with a non-reflection method using delegates. The difference from the solution in the blog post is that SetValue is void , and I get the The type 'System.Void' may not be used as a type argument. exception at the line MethodInfo miConstructedHelper = miGenericHelper.MakeGenericMethod(typeof(G), pMethod.GetParameters()[0].ParameterType, pMethod.ReturnType); . Here's my

Unit testing in C# of private-static method accepting other private-static method as a delegate parameter

给你一囗甜甜゛ 提交于 2019-12-22 08:55:51
问题 What I have: I have a non-static class containing, among others, two private-static methods: one of them can be passed to another one as a delegate parameter: public class MyClass { ... private static string MyMethodToTest(int a, int b, Func<int, int, int> myDelegate) { return "result is " + myDelegate(a, b); } private static int MyDelegateMethod(int a, int b) { return (a + b); } } What I have to do: I have to test (with unit testing) the private-static method MyMethodToTest with passing to

Failed to Understand the Use of Delegates in Real World Scenarios [closed]

房东的猫 提交于 2019-12-22 08:51:04
问题 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 6 years ago . I can't understand the proper use of delegates in .NET world. What can't be solved with Delegates? I want to know what scenario/situation is ideal or candidate for delegate usage. I know LINQ and Lambda expressions all use Delegates behind the scenes. I know how to create and

C++/CLI use of Action<…,…> and Func<…> unsupported?

蹲街弑〆低调 提交于 2019-12-22 08:46:08
问题 it does not look like there is support for the Action and Func delegates in the System namespace in C++/CLI. At least not for multiple generic arguments such as: System::Action<int, int>^ action = nullptr; System::Func<int, int>^ func = nullptr; Both result in errors such as: error C2977: 'System::Action' : too many generic arguments error C2955: 'System::Action' : use of class generic requires generic argument list Only single argument Action works: System::Action<int>^ action = nullptr;

Pass action delegate as parameter in C#

爱⌒轻易说出口 提交于 2019-12-22 08:40:14
问题 I have a method which accepts an Action delegate and executes the given method as shown here: public void ExpMethod(Action inputDel) { inpuDel(); } I can call above given method like this: ExpMethod(() => {/*do something that matters*/}); Everything works fine. So far so good. Now I want to have a method which takes a generic Action delegate as an input parameter - like this: public void ExpGenMethod(Action<string,int> inputDel) { // I don't know how to call the supplied delegate as it

Windows Forms Threading and Events - ListBox updates promptly but progressbar experiences huge delay

*爱你&永不变心* 提交于 2019-12-22 08:39:28
问题 Our team is creating a new recruitment workflow system to replace an old one. I have been tasked with migrating the old data into the new schema. I have decided to do this by creating a small Windows Forms project as the schema are radically different and straight TSQL scripts are not an adequate solution. The main sealed class 'ImportController' that does the work declares the following delegate event: public delegate void ImportProgressEventHandler(object sender, ImportProgressEventArgs e);

Asp.Net - Can the absolute expiry for a Cache with CacheUpdateCallback be smaller than 20 seconds?

混江龙づ霸主 提交于 2019-12-22 08:21:28
问题 I have the a test harness detailed below. This has two labels on the page that are set within the page_load which is hit every second due to the updatepanel and timer. Label1 is set to a datetime value that is stored in the Cache. Label2 is set to the current datetime. The cache is set with an absolute expiry of 5 seconds from now and there is an update callback on the cache to re-set the datetime and make it valid for another 5 seconds. The problem I have is that I'm seeing the cache update