Search Results

Search found 2441 results on 98 pages for 'delegate'.

Page 10/98 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • How can I create a MethodInfo from an Action delegate

    - by Michael Meadows
    I am trying to develop an NUnit addin that dynamically adds test methods to a suite from an object that contains a list of Action delegates. The problem is that NUnit appears to be leaning heavily on reflection to get the job done. Consequently, it looks like there's no simple way to add my Actions directly to the suite. I must, instead, add MethodInfo objects. This would normally work, but the Action delegates are anonymous, so I would have to build the types and methods to accomplish this. I need to find an easier way to do this, without resorting to using Emit. Does anyone know how to easily create MethodInfo instances from Action delegates?

    Read the article

  • Calling UITableViews delegate methods directly.

    - by RickiG
    Hi I was looking for a way to call the edit method directly. - (void)tableView:(UITableView *)theTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath I have all my logic for animating manipulated cells, removing from my model array etc. in this method. It is getting called when a user swipes, adds or rearranges, but I would like to call it manually/directly as a background thread changes my model. I have constructed an NSIndexPath like so: NSIndexPath *path = [NSIndexPath indexPathForRow:i inSection:1]; I just can't figure out how to call something like: [self.tableview commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:path]; Do I need to gain access to the methods of this plain style UITableView in another way? Thanks:)

    Read the article

  • Typesafe fire-and-forget asynchronous delegate invocation in C#

    - by LBushkin
    I recently found myself needing a typesafe "fire-and-forget" mechanism for running code asynchronously. Ideally, what I would want to do is something like: var myAction = (Action)(() => Console.WriteLine("yada yada")); myAction.FireAndForget(); // async invocation Unfortunately, the obvious choice of calling BeginInvoke() without a corresponding EndInvoke() does not work - it results in a slow resource leak (since the asyn state is held by the runtime and never released ... it's expecting an eventual call to EndInvoke(). I also can't run the code on the .NET thread pool because it may take a very long time to complete (it's advised to only run relatively short-lived code on the thread pool) - this makes it impossible to use the ThreadPool.QueueUserWorkItem(). Initially, I only needed this behavior for methods whose signature matches Action, Action<...>, or Func<...>. So I put together a set of extension methods (see listing below) that let me do this without running into the resource leak. There are overloads for each version of Action/Func. Unfortunately, I now want to port this code to .NET 4 where the number of generic parameters on Action and Func have been increased substantially. Before I write a T4 script to generate these, I was also hoping to find a simpler more elegant way to do this. Any ideas are welcome. public static class AsyncExt { public static void FireAndForget( this Action action ) { action.BeginInvoke(OnActionCompleted, action); } public static void FireAndForget<T1>( this Action<T1> action, T1 arg1 ) { action.BeginInvoke(arg1, OnActionCompleted<T1>, action); } public static void FireAndForget<T1,T2>( this Action<T1,T2> action, T1 arg1, T2 arg2 ) { action.BeginInvoke(arg1, arg2, OnActionCompleted<T1, T2>, action); } public static void FireAndForget<TResult>(this Func<TResult> func, TResult arg1) { func.BeginInvoke(OnFuncCompleted<TResult>, func); } public static void FireAndForget<T1,TResult>(this Func<T1, TResult> action, T1 arg1) { action.BeginInvoke(arg1, OnFuncCompleted<T1,TResult>, action); } // more overloads of FireAndForget<..>() for Action<..> and Func<..> private static void OnActionCompleted( IAsyncResult result ) { var action = (Action)result.AsyncState; action.EndInvoke(result); } private static void OnActionCompleted<T1>( IAsyncResult result ) { var action = (Action<T1>)result.AsyncState; action.EndInvoke( result ); } private static void OnActionCompleted<T1,T2>(IAsyncResult result) { var action = (Action<T1,T2>)result.AsyncState; action.EndInvoke(result); } private static void OnFuncCompleted<TResult>( IAsyncResult result ) { var func = (Func<TResult>)result.AsyncState; func.EndInvoke( result ); } private static void OnFuncCompleted<T1,TResult>(IAsyncResult result) { var func = (Func<T1, TResult>)result.AsyncState; func.EndInvoke(result); } // more overloads of OnActionCompleted<> and OnFuncCompleted<> }

    Read the article

  • Reach the end of the tableview without using 'numberOfRowsInSection' delegate method iphone sdk

    - by neha
    Hi all, I want to add a view after the last cell of tableview. I need to define the frame for it. If I want to add something before the first cell, then I can set the frame as refreshHeaderView = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.view.bounds.size.height,320.0f, self.view.bounds.size.height)]; But how to find the y coordinate of the frame of view to be set after the last cell. Thanx in advance.

    Read the article

  • Objective C map view delegate viewForAnnotation for MKAnnotation gets just called after click

    - by user1185486
    I have a simple Map view. It has a method -(void)loadAndDisplayPois{ NSLog(@"loadAndDisplayPois"); if(mapView.annotations.count > 0) [mapView removeAnnotations:mapView.annotations]; self.pois = [self loadPoisFromDatabase]; NSLog(@"self.pois.count: %i", self.pois.count); [mapView addAnnotations:self.pois]; NSLog(@"mapView.annotations.count: %i",mapView.annotations.count);} This method gets called, and I am sure that the method gets called because of the Log, after I downloaded data and saved it into the database. The class which handles the download executes after saving the data to the database [self.senderObj performSelector:@selector(loadAndDisplayPois)]; Where senderObj is the MapViewControlller. The count Log from the pois array shows 4 after the first time I clicked. But no Annotations on the view, because viewForAnnotation is not called (one Annotation in the array ( my current position)). After I execute the method again by clicking a TEST button shows everything on the map. The viewForAnnotation method gets called after viewWillAppear and after I clicked the TEST button. It is driving me nuts since 2 days. I cant anymore ...

    Read the article

  • System.Threading.Timer Doesn't Trigger my TimerCallBack Delegate

    - by Tom Kong
    Hi, I am writing my first Windows Service using C# and I am having some trouble with my Timer class. When the service is started, it runs as expected but the code will not execute again (I want it to run every minute) Please take a quick look at the attached source and let me know if you see any obvious mistakes! TIA using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Linq; using System.ServiceProcess; using System.Text; using System.Threading; using System.IO; namespace CXO001 { public partial class Service1 : ServiceBase { public Service1() { InitializeComponent(); } /* * Aim: To calculate and update the Occupancy values for the different Sites * * Method: Retrieve data every minute, updating a public value which can be polled */ protected override void OnStart(string[] args) { Daemon(); } public void Daemon() { TimerCallback tcb = new TimerCallback(On_Tick); TimeSpan duetime = new TimeSpan(0, 0, 1); TimeSpan interval = new TimeSpan(0, 1, 0); Timer querytimer = new Timer(tcb, null, duetime, interval); } protected override void OnStop() { } static int[] floorplanids = new int[] { 115, 114, 107, 108 }; public static List<Record> Records = new List<Record>(); static bool firstrun = true; public static void On_Tick(object timercallback) { //Update occupancy data for the last minute //Save a copy of the public values to HDD with a timestamp string starttime; if (Records.Count > 0) { starttime = Records.Last().TS; firstrun = false; } else { starttime = DateTime.Today.AddHours(7).ToString(); firstrun = true; } DateTime endtime = DateTime.Now; GetData(starttime, endtime); } public static void GetData(string starttime, DateTime endtime) { string connstr = "Data Source = 192.168.1.123; Initial Catalog = Brickstream_OPS; User Id = Brickstream; Password = bstas;"; DataSet resultds = new DataSet(); //Get the occupancy for each Zone foreach (int zone in floorplanids) { SQL s = new SQL(); string querystr = "SELECT SUM(DIRECTIONAL_METRIC.NUM_TO_ENTER - DIRECTIONAL_METRIC.NUM_TO_EXIT) AS 'Occupancy' FROM REPORT_OBJECT INNER JOIN REPORT_OBJ_METRIC ON REPORT_OBJECT.REPORT_OBJ_ID = REPORT_OBJ_METRIC.REPORT_OBJECT_ID INNER JOIN DIRECTIONAL_METRIC ON REPORT_OBJ_METRIC.REP_OBJ_METRIC_ID = DIRECTIONAL_METRIC.REP_OBJ_METRIC_ID WHERE (REPORT_OBJ_METRIC.M_START_TIME BETWEEN '" + starttime + "' AND '" + endtime.ToString() + "') AND (REPORT_OBJECT.FLOORPLAN_ID = '" + zone + "');"; resultds = s.Go(querystr, connstr, zone.ToString(), resultds); } List<Record> result = new List<Record>(); int c = 0; foreach (DataTable dt in resultds.Tables) { Record r = new Record(); r.TS = DateTime.Now.ToString(); r.Zone = dt.TableName; if (!firstrun) { r.Occupancy = (dt.Rows[0].Field<int>("Occupancy")) + (Records[c].Occupancy); } else { r.Occupancy = dt.Rows[0].Field<int>("Occupancy"); } result.Add(r); c++; } Records = result; MrWriter(); } public static void MrWriter() { StringBuilder output = new StringBuilder("Time,Zone,Occupancy\n"); foreach (Record r in Records) { output.Append(r.TS); output.Append(","); output.Append(r.Zone); output.Append(","); output.Append(r.Occupancy.ToString()); output.Append("\n"); } output.Append(firstrun.ToString()); output.Append(DateTime.Now.ToFileTime()); string filePath = @"C:\temp\CXO.csv"; File.WriteAllText(filePath, output.ToString()); } } }

    Read the article

  • how do I set a delegate in a view that is not my main view

    - by orangecl4now
    I have a xib. the xib has a button that swaps another xib. the second xib has a uitextfield and a uilabel. how do I make the keyboard go away when I'm done typing? what do I need to wire or code? the second xib has it's own class (called CustomSign.m) Inside CustomSign.m, I've implemented the following method -(void)textFieldDidEndEditing:(UITextField *)textField { [customText resignFirstResponder]; signedLabel.text = customText.text; } - (void)awakeFromNib { //assume textField is an ivar that is connected to the textfield in IB [customText setDelegate:self]; } I get the following warning Class "CustomSign" does not implement the UITextFieldDelegate protocol

    Read the article

  • Vb.Net action delegate problem?

    - by Ramesh Vel
    Hi, Am vb.net newbie. This question might be very novice and answered before, but i couldn't find. I was trying the lambda features and got struck here. Private Function HigerOrderTest(highFunction as Func(Of Int16,Int16)) As Action(of String) Dim sam = highFunction(3) Dim DoIt as Action(of String) DoIt = sub(s) console.WriteLine(s) return DoIt End Function I got "Expression expected." at line DoIt = sub(s) console.WriteLine(s). And when i changed this to DoIt = function(s) console.WriteLine(s) i got Expression does not produce a value. error. Whats the problem? Cheers

    Read the article

  • Prevent delegate method from being called too often

    - by Lord Zsolt
    How would you add a delay between certain method being called? This is my code that I want to only trigger 30 times per second: - (void) scrollViewDidScroll: (UIScrollView*)scrollView { [self performSelector:@selector(needsDisplay) withObject:nil afterDelay:0.033]; } - (void) needsDisplay { [captureView setNeedsDisplay]; } If I leave it like this, it only gets called after the user stopped scrolling. What I want to do is call the method when the user is scrolling, but with a delay of 33 milliseconds between each call.

    Read the article

  • C# Property Delegate?

    - by Mark
    In my other methods I could do something like this, public void Add(T item) { if (dispatcher.CheckAccess()) { ... } else { dispatcher.Invoke(new Action<T>(Add), item); } } But how do I invoke a property for a situation like this? public T this[int index] { get { ... } set { if (dispatcher.CheckAccess()) { ... } else { dispatcher.Invoke(???, index); // <-- problem is here } } }

    Read the article

  • Delegate Example From C# In Depth Confusion

    - by ChloeRadshaw
    I am looking at this example: List<Product> products = Product. GetSampleProducts() ; products.Sort( (first, second) => first.Name.CompareTo(second. Name) ) ; foreach (Product product in products) { Console. WriteLine(product) ; } What function is actually called in the API when you do that? Does the compiler create a class which implemnents the IComparer interface? I thought delegates were anonymous methods - Here it seems to be an anonymous interface implementation which is casuing confusion

    Read the article

  • App delegate doesn't work after starting using Storyboards -iOS

    - by user968173
    I have a small problem with my game.. I wanna stop my game whenever it's interrupted. My stopGame method was working when I called it in applicationWillResignActive when I was using xib files. When I changed it to storyboards, it stopped working.. applicationWillResignActive still works with storyboards and my stopGame method is called, but for some reason, my game does not stop.. Has someone faced a problem like this? And possible solutions please.. Thanks in advance..

    Read the article

  • why retain of delegate is wrong what are all alternatives...?

    - by jeeva
    Hi, I have one problem let assume A and B are 2 view controller from A user push to B view controller,In B user starts some download by creating object C(which is NSObject class) and sets B as delegate to C(assign),now user want go back to A then dealloc of B calls object releases, C delegate fails to give call back(crashes).I want to get call and allow user to move to other view controller thats way i am retain the delegate in C class but retain of delegate is wrong ... what are all solutions ... Thanks in Advance.

    Read the article

  • Code Complete 2ed, composition and delegation.

    - by Arlukin
    Hi there. After a couple of weeks reading on this forum I thought it was time for me to do my first post. I'm currently rereading Code Complete. I think it's 15 years since the last time, and I find that I still can't write code ;-) Anyway on page 138 in Code Complete you find this coding horror example. (I have removed some of the code) class Emplyee { public: FullName GetName() const; Address GetAddress() const; PhoneNumber GetWorkPhone() const; ... bool IsZipCodeValid( Address address); ... private: ... } What Steve thinks is bad is that the functions are loosely related. Or has he writes "There's no logical connection between employees and routines that check ZIP codes, phone numbers or job classifications" Ok I totally agree with him. Maybe something like the below example is better. class ZipCode { public: bool IsValid() const; ... } class Address { public: ZipCode GetZipCode() const; ... } class Employee { public: Address GetAddress() const; ... } When checking if the zip is valid you would need to do something like this. employee.GetAddress().GetZipCode().IsValid(); And that is not good regarding to the Law of Demeter ([http://en.wikipedia.org/wiki/Law_of_Demeter][1]). So if you like to remove two of the three dots, you need to use delegation and a couple of wrapper functions like this. class ZipCode { public: bool IsValid(); } class Address { public: ZipCode GetZipCode() const; bool IsZipCodeValid() {return GetZipCode()->IsValid()); } class Employee { public: FullName GetName() const; Address GetAddress() const; bool IsZipCodeValid() {return GetAddress()->IsZipCodeValid()); PhoneNumber GetWorkPhone() const; } employee.IsZipCodeValid(); But then again you have routines that has no logical connection. I personally think that all three examples in this post are bad. Is it some other way that I haven't thougt about? //Daniel

    Read the article

  • Moq a function with 5+ parameters and access invocation arguments.

    - by beerncircus
    I have a function I want to Moq. The problem is that it takes 5 parameters. The framework only contains Action<T1,T2,T3,T4> and Moq's generic CallBack() only overloads Action and the four generic versions. Is there an elegant workaround for this? This is what I want to do: public class Filter : IFilter { public int Filter(int i1, int i2, int i3, int i4, int i5){return 0;} } //Moq code: var mocker = new Mock<IFilter>(); mocker.Setup(x => x.Filter( It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()) .Callback ( (int i1, int i2, int i3, int i4, int i5) => i1 * 2 ); Moq doesn't allow this because there is no generic Action that takes 5+ parameters. I've resorted to making my own stub. Obviously, it would be better to use Moq with all of its verifications, etc.

    Read the article

  • Delegates in Action -Help

    - by Amutha
    I am learning delegates.I am very curious to apply delegates to the following chain-of-responsibility pattern. Kindly help me the way to apply delegates to the following piece. Thanks in advance.Thanks for your effort. #region Chain of Responsibility Pattern namespace Chain { public class Player { public string Name { get; set; } public int Score { get; set; } } public abstract class PlayerHandler { protected PlayerHandler _Successor = null; public abstract void HandlePlayer(Player _player); public void SetupHandler(PlayerHandler _handler) { _Successor = _handler; } } public class Employee : PlayerHandler { public override void HandlePlayer(Player _player) { if (_player.Score <= 100) { MessageBox.Show(string.Format("{0} is greeted by Employee", _player.Name)); } else { _Successor.HandlePlayer(_player); } } } public class Supervisor : PlayerHandler { public override void HandlePlayer(Player _player) { if (_player.Score >100 && _player.Score<=200) { MessageBox.Show(string.Format("{0} is greeted by Supervisor", _player.Name)); } else { _Successor.HandlePlayer(_player); } } } public class Manager : PlayerHandler { public override void HandlePlayer(Player _player) { if (_player.Score > 200) { MessageBox.Show(string.Format("{0} is greeted by Manager", _player.Name)); } else { MessageBox.Show(string.Format("{0} got low score", _player.Name)); } } } } #endregion #region Main() void Main() { Chain.Player p1 = new Chain.Player(); p1.Name = "Jon"; p1.Score = 100; Chain.Player p2 = new Chain.Player(); p2.Name = "William"; p2.Score = 170; Chain.Player p3 = new Chain.Player(); p3.Name = "Robert"; p3.Score = 300; Chain.Employee emp = new Chain.Employee(); Chain.Manager mgr = new Chain.Manager(); Chain.Supervisor sup = new Chain.Supervisor(); emp.SetupHandler(sup); sup.SetupHandler(mgr); emp.HandlePlayer(p1); emp.HandlePlayer(p2); emp.HandlePlayer(p3); } #endregion

    Read the article

  • XMLEncoder and PersistenceDelegate

    - by Johannes Rössel
    I'm trying to use XMLEncoder to write an object graph (tree in my case) to a file. However, one class contained in it is not actually a Java bean and I don't particularly like making its guts publicly accessible. It's accessed more like a list and has appropriate add methods. I've already written a custom PersistenceDelegate to deal with that. However, is there any way for XMLEncoder to pick it up on its own or do I really need to add it whenever I use an encoder to write a graph that may contain said class?

    Read the article

  • setDelegate explanation

    - by mac
    Hi i am new to iphone developement , can any one explain me , why setDelegate is used, where we should use it. [request setDelegate:sender]; thanks in advance.

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >