Search Results

Search found 10381 results on 416 pages for 'delegate and events'.

Page 37/416 | < Previous Page | 33 34 35 36 37 38 39 40 41 42 43 44  | Next Page >

  • 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

  • Display Events on PHP Calendar

    - by jl
    Hi, I would like to ask if I have a table of events on my database, e.g. description | startdt | enddt event1 | 2010-04-01 10:00:00 | 2010-04-01 13:00:00 event2 | 2010-04-09 14:00:00 | 2010-04-09 18:00:00 event3 | 2010-04-30 11:00:00 | 2010-05-02 16:00:00 I have already created a php calendar, how can I display these above events onto my calendar, so that it will look something like the google calendar? e.g. on the for 2010-04-01, it will display "event1" on the month calendar. Thank you.

    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

  • 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

  • Using AMQP to collect events

    - by synapse
    Does AMQP has any advantages over an ad-hoc implementation for a simple stats gathering scenario? It works like this - clients send events (more than we care to put into persistent storage) to (several) web workers, the workers aggrregate them and write to a single database. I don't think I should consider using AMQP for this because I'll still need web workers to receive events from clients through HTTP and to publish them. Am I missing something?

    Read the article

  • GWT: Getting events in a button in a panel used as a Table cell

    - by mjeffw
    I'm using GWT 1.6. I am creating a panel that contains a Button and a Label, which I then add to a FlexTable as one of its cells. The Button is not receiving any Click events. I see that the table supports determining which Cell is clicked on, but in this case, I want the Mouse events to propagate to the various widgets inside the cell. Any idea on how to do that?

    Read the article

  • Using ManualResetEvent to wait for multiple Image.ImageOpened events

    - by umlgorithm
    Dictionary<Image, ManualResetEvent> waitHandleMap = new Dictionary<Image, ManualResetEvent>(); List<Image> images = GetImagesWhichAreAlreadyInVisualTree(); foreach (var image in images) { image.Source = new BitmapImage(new Uri("some_valid_image_url")); waitHandleMap.Add(image, new ManualResetEvent(false)); image.ImageOpened += delegate { waitHandleMap[image].Set(); }; image.ImageFailed += delegate { waitHandleMap[image].Set(); }; } WaitHandle.WaitAll(waitHandleMap.Values.ToArray()); WaitHandle.WaitAll blocks the current UI thread, so ImageOpened/ImageFailed events would never get fired. Could you suggest me an easy workaround to wait for the multiple ui events?

    Read the article

  • jquery event listening, non-standard events

    - by Stacey
    I'm attempting to build a way for my selectors to 'listen' to 'global' events that are beyond the typical 'click' 'change' 'submit' etc. I've explored the various 'eventmanagers' that I could find, and they're all still designed for forms. Is there any way to do something like this for non-standard (i.e. custom) events? The goal is to have selectors subscribe to an event, and then be able to trigger it in one place and it will raise it for everything subscribed to it.

    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# Events and Lambdas, alternative to null check?

    - by Eugarps
    Does anybody see any drawbacks? It should be noted that you can't remove anonymous methods from an event delegate list, I'm aware of that (actually that was the conceptual motivation for this). The goal here is an alternative to: if (onFoo != null) onFoo.Invoke(this, null); And the code: public delegate void FooDelegate(object sender, EventArgs e); public class EventTest { public EventTest() { onFoo += (p,q) => { }; } public FireFoo() { onFoo.Invoke(this, null); } public event FooDelegate onFoo; }

    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

  • Variable type for Application on Time Events [on hold]

    - by user2931226
    Been Trying to figure out how to go about setting a Variable for some Application On Time events, But still not confident to do it. These events (Macro's) get called by another Macro then they wait for 10 - 20 minutes, then they don't Run. So have read that (EarliestTime argument) should be assigned to a variable to store it other wise it looses it when other things are running Help appreciated Thanks Sub settimers() Application.OnTime TimeValue(Range("$X$9").Text), "StartBlink" Application.OnTime TimeValue(Range("$W$11").Text), "StopBlink" End Sub

    Read the article

  • UIView capturing all events

    - by Josh P.
    I have a UIView that uses several UIGestureRecognizers and this view again has at least one child view that contains a MPMoviePlayerController. When a touch event occurs over the movie player, the main view seems to 'eat' all the events, leaving the media player idle. How can I make sure that the events are delivered correctly to the player?

    Read the article

  • Raising events vs direct method calls differences

    - by dotnetdev
    Hi Raising an event, will call its event handler. eg http://msdn.microsoft.com/en-us/library/aa645739%28VS.71%29.aspx What is the difference between using the events mechanism and direct calls to other methods (eg if a condition is met in method A(), call B() )? And what is the difference between consuming and raising events? Thanks

    Read the article

< Previous Page | 33 34 35 36 37 38 39 40 41 42 43 44  | Next Page >