Search Results

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

Page 117/416 | < Previous Page | 113 114 115 116 117 118 119 120 121 122 123 124  | Next Page >

  • Why can't c# use inline anonymous lambdas or delegates?

    - by Samuel Meacham
    I hope I worded the title of my question appropriately. In c# I can use lambdas (as delegates), or the older delegate syntax to do this: Func<string> fnHello = () => "hello"; Console.WriteLine(fnHello()); Func<string> fnHello2 = delegate() { return "hello 2"; }; Console.WriteLine(fnHello2()); So why can't I "inline" the lambda or the delegate body, and avoid capturing it in a named variable (making it anonymous)? // Inline anonymous lambda not allowed Console.WriteLine( (() => "hello inline lambda")() ); // Inline anonymous delegate not allowed Console.WriteLine( (delegate() { return "hello inline delegate"; })() ); An example that works in javascript (just for comparison) is: alert( (function(){ return "hello inline anonymous function from javascript"; })() ); Which produces the expected alert box. UPDATE: It seems you can have an inline anonymous lambda in C#, if you cast appropriately, but the amount of ()'s starts to make it unruly. // Inline anonymous lambda with appropriate cast IS allowed Console.WriteLine( ((Func<string>)(() => "hello inline anonymous lambda"))() ); Perhaps the compiler can't infer the sig of the anonymous delegate to know which Console.WriteLine() you're trying to call? Does anyone know why this specific cast is required?

    Read the article

  • Properly declare delegation in Objective C (iPhone)

    - by Gordon Fontenot
    Ok, This has been explained a few times (I got most of the way there using this post on SO), but I am missing something. I am able to compile cleanly, and able to set the delegate as well as call methods from the delegate, but I'm getting a warning on build: No definition of protocol 'DetailViewControllerDelegate' is found I have a DetailViewController and a RootViewController only. I am calling a method in RootViewController from DetailViewController. I have the delegate set up as so: In RootViewController.h: #import "DetailViewController.h" @interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate, DetailViewControllerDelegate> //Error shows up here { //Some Stuff Here } //Some other stuff here @end In RootViewController.m I define the delegate when I create the view using detailViewController.delegate = self In DetailViewController.h: @protocol DetailViewControllerDelegate; #import "RootViewController.h" @interface DetailViewController : UITableViewController <UITextFieldDelegate> { id <DetailViewControllerDelegate> delegate; } @property (nonatomic, assign) id <DetailViewControllerDelegate> delegate; @end @protocol DetailViewControllerDelegate //some methods that reside in RootViewController.m @end I feel weird about declaring the protocol above the import in DetailViewController.h, but if I don't it doesn't build. Like I said, the methods are called fine, and there are no other errors going on. What am I missing here?

    Read the article

  • Getting around IBActions limited scope

    - by Septih
    Hello, I have an NSCollectionView and the view is an NSBox with a label and an NSButton. I want a double click or a click of the NSButton to tell the controller to perform an action with the represented object of the NSCollectionViewItem. The Item View is has been subclassed, the code is as follows: #import <Cocoa/Cocoa.h> #import "WizardItem.h" @interface WizardItemView : NSBox { id delegate; IBOutlet NSCollectionViewItem * viewItem; WizardItem * wizardItem; } @property(readwrite,retain) WizardItem * wizardItem; @property(readwrite,retain) id delegate; -(IBAction)start:(id)sender; @end #import "WizardItemView.h" @implementation WizardItemView @synthesize wizardItem, delegate; -(void)awakeFromNib { [self bind:@"wizardItem" toObject:viewItem withKeyPath:@"representedObject" options:nil]; } -(void)mouseDown:(NSEvent *)event { [super mouseDown:event]; if([event clickCount] > 1) { [delegate performAction:[wizardItem action]]; } } -(IBAction)start:(id)sender { [delegate performAction:[wizardItem action]]; } @end The problem I've run into is that as an IBAction, the only things in the scope of -start are the things that have been bound in IB, so delegate and viewItem. This means that I cannot get at the represented object to send it to the delegate. Is there a way around this limited scope or a better way or getting hold of the represented object? Thanks.

    Read the article

  • Making a Statement: How to retrieve the T-SQL statement that caused an event

    - by extended_events
    If you’ve done any troubleshooting of T-SQL, you know that sooner or later, probably sooner, you’re going to want to take a look at the actual statements you’re dealing with. In extended events we offer an action (See the BOL topic that covers Extended Events Objects for a description of actions) named sql_text that seems like it is just the ticket. Well…not always – sounds like a good reason for a blog post. When is a statement not THE statement? The sql_text action returns the same information that is returned from DBCC INPUTBUFFER, which may or may not be what you want. For example, if you execute a stored procedure, the sql_text action will return something along the lines of “EXEC sp_notwhatiwanted” assuming that is the statement you sent from the client. Often times folks would like something more specific, like the actual statements that are being run from within the stored procedure or batch. Enter the stack Extended events offers another action, this one with the descriptive name of tsql_stack, that includes the sql_handle and offset information about the statements being run when an event occurs. With the sql_handle and offset values you can retrieve the specific statement you seek using the DMV dm_exec_sql_statement. The BOL topic for dm_exec_sql_statement provides an example for how to extract this information, so I’ll cover the gymnastics required to get the sql_handle and offset values out of the tsql_stack data collected by the action. I’m the first to admit that this isn’t pretty, but this is what we have in SQL Server 2008 and 2008 R2. We will be making it easier to get statement level information in the next major release of SQL Server. The sample code For this example I have a stored procedure that includes multiple statements and I have a need to differentiate between those two statements in my tracing. I’m going to track two events: module_end tracks the completion of the stored procedure execution and sp_statement_completed tracks the execution of each statement within a stored procedure. I’m adding the tsql_stack events (since that’s the topic of this post) and the sql_text action for comparison sake. (If you have questions about creating event sessions, check out Pedro’s post Introduction to Extended Events.) USE AdventureWorks2008GO -- Test SPCREATE PROCEDURE sp_multiple_statementsASSELECT 'This is the first statement'SELECT 'this is the second statement'GO -- Create a session to look at the spCREATE EVENT SESSION track_sprocs ON SERVERADD EVENT sqlserver.module_end (ACTION (sqlserver.tsql_stack, sqlserver.sql_text)),ADD EVENT sqlserver.sp_statement_completed (ACTION (sqlserver.tsql_stack, sqlserver.sql_text))ADD TARGET package0.ring_bufferWITH (MAX_DISPATCH_LATENCY = 1 SECONDS)GO -- Start the sessionALTER EVENT SESSION track_sprocs ON SERVERSTATE = STARTGO -- Run the test procedureEXEC sp_multiple_statementsGO -- Stop collection of events but maintain ring bufferALTER EVENT SESSION track_sprocs ON SERVERDROP EVENT sqlserver.module_end,DROP EVENT sqlserver.sp_statement_completedGO Aside: Altering the session to drop the events is a neat little trick that allows me to stop collection of events while keeping in-memory targets such as the ring buffer available for use. If you stop the session the in-memory target data is lost. Now that we’ve collected some events related to running the stored procedure, we need to do some processing of the data. I’m going to do this in multiple steps using temporary tables so you can see what’s going on; kind of like having to “show your work” on a math test. The first step is to just cast the target data into XML so I can work with it. After that you can pull out the interesting columns, for our purposes I’m going to limit the output to just the event name, object name, stack and sql text. You can see that I’ve don a second CAST, this time of the tsql_stack column, so that I can further process this data. -- Store the XML data to a temp tableSELECT CAST( t.target_data AS XML) xml_dataINTO #xml_event_dataFROM sys.dm_xe_sessions s INNER JOIN sys.dm_xe_session_targets t    ON s.address = t.event_session_addressWHERE s.name = 'track_sprocs' SELECT * FROM #xml_event_data -- Parse the column data out of the XML blockSELECT    event_xml.value('(./@name)', 'varchar(100)') as [event_name],    event_xml.value('(./data[@name="object_name"]/value)[1]', 'varchar(255)') as [object_name],    CAST(event_xml.value('(./action[@name="tsql_stack"]/value)[1]','varchar(MAX)') as XML) as [stack_xml],    event_xml.value('(./action[@name="sql_text"]/value)[1]', 'varchar(max)') as [sql_text]INTO #event_dataFROM #xml_event_data    CROSS APPLY xml_data.nodes('//event') n (event_xml) SELECT * FROM #event_data event_name object_name stack_xml sql_text sp_statement_completed NULL <frame level="1" handle="0x03000500D0057C1403B79600669D00000100000000000000" line="4" offsetStart="94" offsetEnd="172" /><frame level="2" handle="0x01000500CF3F0331B05EC084000000000000000000000000" line="1" offsetStart="0" offsetEnd="-1" /> EXEC sp_multiple_statements sp_statement_completed NULL <frame level="1" handle="0x03000500D0057C1403B79600669D00000100000000000000" line="6" offsetStart="174" offsetEnd="-1" /><frame level="2" handle="0x01000500CF3F0331B05EC084000000000000000000000000" line="1" offsetStart="0" offsetEnd="-1" /> EXEC sp_multiple_statements module_end sp_multiple_statements <frame level="1" handle="0x03000500D0057C1403B79600669D00000100000000000000" line="0" offsetStart="0" offsetEnd="0" /><frame level="2" handle="0x01000500CF3F0331B05EC084000000000000000000000000" line="1" offsetStart="0" offsetEnd="-1" /> EXEC sp_multiple_statements After parsing the columns it’s easier to see what is recorded. You can see that I got back two sp_statement_completed events, which makes sense given the test procedure I’m running, and I got back a single module_end for the entire statement. As described, the sql_text isn’t telling me what I really want to know for the first two events so a little extra effort is required. -- Parse the tsql stack information into columnsSELECT    event_name,    object_name,    frame_xml.value('(./@level)', 'int') as [frame_level],    frame_xml.value('(./@handle)', 'varchar(MAX)') as [sql_handle],    frame_xml.value('(./@offsetStart)', 'int') as [offset_start],    frame_xml.value('(./@offsetEnd)', 'int') as [offset_end]INTO #stack_data    FROM #event_data        CROSS APPLY    stack_xml.nodes('//frame') n (frame_xml)    SELECT * from #stack_data event_name object_name frame_level sql_handle offset_start offset_end sp_statement_completed NULL 1 0x03000500D0057C1403B79600669D00000100000000000000 94 172 sp_statement_completed NULL 2 0x01000500CF3F0331B05EC084000000000000000000000000 0 -1 sp_statement_completed NULL 1 0x03000500D0057C1403B79600669D00000100000000000000 174 -1 sp_statement_completed NULL 2 0x01000500CF3F0331B05EC084000000000000000000000000 0 -1 module_end sp_multiple_statements 1 0x03000500D0057C1403B79600669D00000100000000000000 0 0 module_end sp_multiple_statements 2 0x01000500CF3F0331B05EC084000000000000000000000000 0 -1 Parsing out the stack information doubles the fun and I get two rows for each event. If you examine the stack from the previous table, you can see that each stack has two frames and my query is parsing each event into frames, so this is expected. There is nothing magic about the two frames, that’s just how many I get for this example, it could be fewer or more depending on your statements. The key point here is that I now have a sql_handle and the offset values for those handles, so I can use dm_exec_sql_statement to get the actual statement. Just a reminder, this DMV can only return what is in the cache – if you have old data it’s possible your statements have been ejected from the cache. “Old” is a relative term when talking about caches and can be impacted by server load and how often your statement is actually used. As with most things in life, your mileage may vary. SELECT    qs.*,     SUBSTRING(st.text, (qs.offset_start/2)+1,         ((CASE qs.offset_end          WHEN -1 THEN DATALENGTH(st.text)         ELSE qs.offset_end         END - qs.offset_start)/2) + 1) AS statement_textFROM #stack_data AS qsCROSS APPLY sys.dm_exec_sql_text(CONVERT(varbinary(max),sql_handle,1)) AS st event_name object_name frame_level sql_handle offset_start offset_end statement_text sp_statement_completed NULL 1 0x03000500D0057C1403B79600669D00000100000000000000 94 172 SELECT 'This is the first statement' sp_statement_completed NULL 1 0x03000500D0057C1403B79600669D00000100000000000000 174 -1 SELECT 'this is the second statement' module_end sp_multiple_statements 1 0x03000500D0057C1403B79600669D00000100000000000000 0 0 C Now that looks more like what we were after, the statement_text field is showing the actual statement being run when the sp_statement_completed event occurs. You’ll notice that it’s back down to one row per event, what happened to frame 2? The short answer is, “I don’t know.” In SQL Server 2008 nothing is returned from dm_exec_sql_statement for the second frame and I believe this to be a bug; this behavior has changed in the next major release and I see the actual statement run from the client in frame 2. (In other words I see the same statement that is returned by the sql_text action  or DBCC INPUTBUFFER) There is also something odd going on with frame 1 returned from the module_end event; you can see that the offset values are both 0 and only the first letter of the statement is returned. It seems like the offset_end should actually be –1 in this case and I’m not sure why it’s not returning this correctly. This behavior is being investigated and will hopefully be corrected in the next major version. You can workaround this final oddity by ignoring the offsets and just returning the entire cached statement. SELECT    event_name,    sql_handle,    ts.textFROM #stack_data    CROSS APPLY sys.dm_exec_sql_text(CONVERT(varbinary(max),sql_handle,1)) as ts event_name sql_handle text sp_statement_completed 0x0300070025999F11776BAF006F9D00000100000000000000 CREATE PROCEDURE sp_multiple_statements AS SELECT 'This is the first statement' SELECT 'this is the second statement' sp_statement_completed 0x0300070025999F11776BAF006F9D00000100000000000000 CREATE PROCEDURE sp_multiple_statements AS SELECT 'This is the first statement' SELECT 'this is the second statement' module_end 0x0300070025999F11776BAF006F9D00000100000000000000 CREATE PROCEDURE sp_multiple_statements AS SELECT 'This is the first statement' SELECT 'this is the second statement' Obviously this gives more than you want for the sp_statement_completed events, but it’s the right information for module_end. I leave it to you to determine when this information is needed and use the workaround when appropriate. Aside: You might think it’s odd that I’m showing apparent bugs with my samples, but you’re going to see this behavior if you use this method, so you need to know about it.I’m all about transparency. Happy Eventing- Mike Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!

    Read the article

  • How to track Google Analytics Events in Server Side asp.net?

    - by Raj
    Hello, Is there a way to track Google Analytics Events from Server Side in ASP.NET, the requirement is the the Event should be tracked on button click after some functionalities are executed on Serverside. ? OnClientClick of button, we cannot fulfill this requirement completely as some time serverside functionalities can fail but the event will get tracked in Google? Please help me in this regard. Appreciate expert answers. Thanks in Advance, Raj

    Read the article

  • What is the delegate method that is called when an MKPinAnnotationView is touched?

    - by Jake Schwartz
    I have been searching for this all night and I have just so frustrated. When a MKPinAnnotationView is clicked, the name and the subtitle comes up. I also want to center that point on the view. I figured there was some method I had to override because the information that pops up happened without me having to code it. Hopefully this was clear enough for you all. And in the mean time, I feel like there is some hidden guide on this use of MKMaps and other classes. Either that or it is terribly documented because I am having a lot of trouble finding information. Thanks.

    Read the article

  • are scala's mouse events working? how?

    - by coubeatczech
    Hi, I'm trying to create link-like label in scala. But no mouse events works for me. How are they supposed to work? class Hyperlink extends Label{ text = "hyperlink" reactions += { case MouseClicked(_,_,_,_,_) => println("mouse clicked")}} I put this in some panel and click over the label like a pro minesweeper player... and nothing shows up in console. Why?

    Read the article

  • How can I simulate all mouse and keyboard events in Qt that works on Linux and Windows?

    - by S.Mohammadi
    Problem: I have a device that send to me some commands (e.g: 1,2,3,...), i want simulate mouse and keyboard events according to received commands in Both Linux OS and Windows OS. I worked with bool QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority = Qt::NormalEventPriority) but i don't know what receiver pass to it and i has problem with MouseMove action with it. I found this help that works good in linux OS, but i have problem with this help approach in Windows OS. Is there any approach that works in both OS? Thanks for your attention.

    Read the article

  • ASP.Net MVC - What replaces events to support loose coupling?

    - by James
    What feature(s) of ASP.Net MVC can replace the way events can be used in Webforms to support loosely coupled components. For example, take a simple pager control: A page number is clicked Pager fires off a "PageChange" event with the new page number This subscribing page/control received the event and handles initiating a call to fetch and bind new data. What tools are available in ASP.Net MVC to support Loose coupling Component re-usability Separation of logic for a single page/view (such a very complex "portal" type page).

    Read the article

  • MySQL table organization and optimization (Rails)

    - by aguynamedloren
    I've been learning Ruby on Rails over the past few months with no prior programming experience. Lately, I've been thinking about database optimization and table organization. I know there are great books on the subject, but I typically learn by example / as I go. Here's a hypothetical situation: Let's say I am building a social network for a niche community with 250,000 members (users). The users have the ability to attend events. Let's say there are 50,000 past/present/future events. Much like Facebook events, a user can attend any number of events and an event can have any number of attendees. In the database, there would be a table for users and a table for events. Somehow I would have to create an association between the users and events. I could create an "events" column in the users table such that each user row would contain a hash of event IDs, or I could create an "attendees" column in the events table such that each event row would contain a hash of user IDs. Neither of these solutions seem ideal, however. On a users profile page, I want to display the list of events they are associated with, which would require scanning the 50,000 event rows for the user ID of said user if I include an "attendees" column in the events table. Likewise, on an event page, I want to display a list of attendees for the event, which would require scanning the 250,000 user rows for the event ID of said event if I include an "events" column in the users table. Option 3 would be to create a third table that contains the attendee information for each and every event - but I don't see how this would solve any problems. Are these non-issues? Rails makes accessing all of this information easy, but I guess I'm worried about scale. It is entirely possible that I am under-estimating the speed and processing power of modern databases / servers / etc. How long would it take to scan 250,000 user rows for specific event IDs - 10ms? 100ms? 1,000ms? I guess that's not that bad. Am I just over-thinking this?

    Read the article

  • Any good books out there for advanced concepts like lambdas, delegates, events etc?

    - by they_soft
    I've read about these features but I don't think I've seen enough to consistently apply them in my coding, eg "This would be better done with a delegate than with my other, outdated approach". I know what they do, but I want more examples of use cases, or want some heuristic to help me think in terms of such features. All the books I've seen either focus only on the basics or just mention the features as part of the language. Is there any book out there that deals with this? Preferably C# or language agnostic.

    Read the article

  • Algorithm: how to check intersections of recurring events definitions?

    - by glaz666
    The question comes from MS Outlook calendar behavior. Imagine I have two recurring events (starting from today): "each second Monday" and "every odd date". Is there any way to check intersections and/or find the first intersecting date algorithmically without brute-forcing over each date? Definitions can be made in CRON's notations or ICal notation. I think it doesn't matter. Are there any solutions for this in Gregorian calendar?

    Read the article

  • pushing view controller inside a tab bar from app delegate, after a notification.

    - by shani
    hi i have an app with tab bar and a navigation controller inside every tab. i have set a notification that when it lunches the user can get lunch the app by pressing the action on the alert. i want to redirect the user to one of the views inside one of the controllers. i have tried this: (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif { NSArray *data = [notif.userInfo objectForKey:@"todoDate"]; NSInteger ind = [[data objectAtIndex:2] integerValue]; QuickViewController *detailViewController ; detailViewController = [[QuickViewController alloc] initWithNibName:@"QuickViewController" bundle:nil]; detailViewController.title = @"Edit"; detailViewController.personName = [data objectAtIndex:0]; detailViewController.DelitionDate=[data objectAtIndex:1]; detailViewController.personCategory=@"NO Category"; detailViewController.personID = ind r ; rootControler.selectedIndex = 1; [rootControler.tabBarController.selectedViewController.navigationController pushViewController:detailViewController animated:YES]; } but nothing is happening (no crashing) except of the :rootControler.selectedIndex = 1; when i tried : presentModalViewController i got the view perfectly but without the navigation controller. thanks shani

    Read the article

  • Can you have too many Delegate.BeginInvoke calls at once?

    - by stewsha
    I am cleaning up some old code converting it to work asynchronously. psDelegate.GetStops decStops = psLoadRetrieve.GetLoadStopsByLoadID; var arStops = decStops.BeginInvoke(loadID, null, null); WaitHandle.WaitAll(new WaitHandle[] { arStops.AsyncWaitHandle }); var stops = decStops.EndInvoke(arStops); Above is a single example of what I am doing for asynchronous work. My plan is to have close to 20 different delegates running. All will call BeginInvoke and wait until they are all complete before calling EndInvoke. My question is will having so many delegates running cause problems? I understand that BeginInvoke uses the ThreadPool to do work and that has a limit of 25 threads. 20 is under that limit but it is very likely that other parts of the system could be using any number of threads from the ThreadPool as well. Thanks!

    Read the article

  • Is there a way to determine the Variance of an Interface / Delegate in C# 4.0?

    - by BFree
    So now that we have generic Covariance and Contravariance on interfaces and delegates in C#, I was just curious if given a Type, you can figure out the covariance/contravariance of its generic arguments. I started trying to write my own implementation, which would look through all of the methods on a given type and see if the return types and or arguments match the types in the generic arguments. The problem is that even if I have this: public interface IFoo<T> { void DoSomething(T item); } using my logic, it LOOKS like it should be contravariant, but since we didn't actually specify: public interface IFoo<in T> { void DoSomething(T item); } (the in parameter) it isn't actually contravariant. Which leads to my question: Is there a way to determine the variance of generic parameters?

    Read the article

  • Reason for getting error in Reverse Geocoder Delegate method in the morning times.

    - by Srilakshmi
    - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error { NSLog(@"reverseGeocoder:%@ didFailWithError:%@", geocoder, error); } This method is getting called in morning times and it is not showing the placemark while running the application in simulator. From Afternoon it is showing the placemark as "Cupertino". Will you give me the reason for not getting the placeMark at morning times?

    Read the article

  • How do I combine similar method calls into a delegate pattern?

    - by Daniel T.
    I have three methods: public void Save<T>(T entity) { using (new Transaction()) { Session.Save(entity); } } public void Create<T>(T entity) { using (new Transaction()) { Session.Create(entity); } } public void Delete<T>(T entity) { using (new Transaction()) { Session.Delete(entity); } } As you can see, the only thing that differs is the method call inside the using block. How can I rewrite this so it's something like this instead: public void Save<T>(T entity) { TransactionWrapper(Session.Save(entity)); } public void Create<T>(T entity) { TransactionWrapper(Session.Create(entity)); } public void Save<T>(T entity) { TransactionWrapper(Session.Save(entity)); } So in other words, I pass a method call as a parameter, and the TransactionWrapper method wraps a transaction around the method call.

    Read the article

  • Is there a way to detect non-movement (touch events) ?

    - by hyn
    Is there a way to detect a finger's non-movement by using a combination of UITouch events? The event methods touchesEnded and touchesCancelled are only fired when the event is cancelled or the finger lifted. I would like to know when a touch has stopped moving, even while it is still touching the screen.

    Read the article

  • Is there a better way than a sequence of if's to handle events?

    - by Matt
    I recently ran across several objects implemented to handle events with a hard coded mapping using this pattern: public void handleEvent(Event event) { if(event.getCode() == SOME_STATIC_EVENT) doSomething(event); if(event.getCode() == ANOTHER_STATIC_EVENT) doSomethingElse(event); } where doSomething functions are implemented as methods of the same class. In hopes of striving for looser coupling, how would you suggest abstracting out this pattern? Also, what's the best approach for mapping 0..N functions to a fired event?

    Read the article

  • Use .net reactive in silverlight to generate multiple events.

    - by Mrt
    I have a method in a silverlight application. I want to start calling this method when an event occurs (mouse move), and continue to call this method every 1 second until a simple boolean condition changes. Is this possible ? I can't work out how to get the rx to generate multiple 'events' from the single event

    Read the article

< Previous Page | 113 114 115 116 117 118 119 120 121 122 123 124  | Next Page >