Search Results

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

Page 78/416 | < Previous Page | 74 75 76 77 78 79 80 81 82 83 84 85  | Next Page >

  • Can i execute the events in sequence in jquery

    - by Mirage
    I am using accordians. I want that if someone click on hyperlink inside the accordion , then that accordion should slide up slowly and only after that the nect accordion falls down or open $(".accord").live('click', function(){ $('#rr1').next().slideUp('slow'); $('#rr3').next().slideDown('slow'); But i have seen that the other accordion starts opening up at the same time when the other is closing. It it something related to asynchronous thing. I don't know });

    Read the article

  • C# How to Identify Caller for Template Events

    - by mikeknoop
    I have a ListBox container data bound and templatized as so: <ListBox x:Name="ListBox" ItemsSource="{Binding Source={StaticResource List}}" ItemTemplate="{StaticResource ListTemplate}"> </ListBox> Within my ListTemplate resource, I define a Grid which contains a few child elements. I have setup a click event handler on one of child elements. The event hander is not row-specific, and I need a (best practice) way of identifying which row in the ListBox the event fired upon. From my data source, I have an unique ID which corresponds to the row. I do not currently expose this ID in the data binding, though could. Ideally I would like the event handler to be able to identify the ID of the row the event was fired upon. Thank you!

    Read the article

  • OSX: Programmatically added subviews not responding to mouse down events

    - by BigCola
    I have 3 subclasses: a Block class, a Row class and a Table class. All are subclasses of NSView. I have a Table added with IB which programmatically displays 8 rows, each of which displays 8 blocks. I overrode the mouseDown: method in Block to change the background color to red, but it doesn't work. Still if I add a block directly on top of the Table with IB it does work so I can't understand why it won't work in the first case. Here's the implementation code for Block and Row (Table's implementation works the same way as Row's): //block.m - (void)drawRect:(NSRect)dirtyRect { [color set]; [NSBezierPath fillRect:dirtyRect]; } -(void)mouseDown:(NSEvent *)theEvent { color = [NSColor redColor]; checked = YES; [self setNeedsDisplay:YES]; } //row.m - (void)drawRect:(NSRect)dirtyRect { [[NSColor blueColor] set]; [NSBezierPath fillRect:dirtyRect]; int x; for(x=0; x<8; x++){ int margin = x*2; NSRect rect = NSMakeRect(0, 50*x+margin, 50, 50); Block *block = [[Block alloc] initWithFrame:rect]; [self addSubview:block]; } }

    Read the article

  • Jquery adding events

    - by JBone
    I want to add an event handler to some dynamically added elements. I simplified my problem into the basic code below. I am using the new JQuery 1.7 on feature to say "hey for all labels in the CancelSurvey id element call this notify function when they are clicked." function notify(event) { console.log(event.data.name); } $('#CancelSurvey').on('click', 'label', { name: $(this).attr("id") }, notify); I want to pass the id of the label as parameter "name". When I try to alert this it is undefined (they are defined in the html created). I believe that using the $(this) is not referencing the label selector in this case. It actually seems to be referencing the document itself. Any ideas on how to accomplish this?

    Read the article

  • Converting button events etc to ASP.NET MVC

    - by Sophie88
    Given an asp.net webform page which does something like asp.net <asp:textbox id="txtA" runat="server" /> <asp:textbox id="txtB" runat="server" /> <asp:button id="btnAddTogether" runat="server" text="Go" onclick="btn_Click"/> <asp:textbox id="txtResult" runat="server" /> code behind protected void btn_Click(...) { txtResult.Text = txtA.Text + txtB.Text; } How would I convert this to ASP.NET MVC. It's a pretty trivial example, but I'm not sure about how to change my way of thinking.

    Read the article

  • Google Analytics: Do unique events report as unique visits when triggered on pages other than your own domain?

    - by Jesse Gardner
    We just recently attached a SWF to our Brightcove video player to report various events back to Google Analytics. We're also tracking page views with a standard GA snippet on the page where the player is embedded. As I understand it, because a unique has already been recorded for the page, any event being triggered by the player is getting associated with that unique. However, we allow people to embed the video player on other websites. All of the event data started pouring into the Events section as expected, but we noticed a dramatic uptick in unique visitors on the site (nearly double) while the pageview count stayed relatively unchanged. Disabling event tracking brought the traffic back down to average levels. I should also add that in the Pages section of Event tracking we're seeing URLs for other sites where the player has been embedded; but this data isn't showing up in the Content section. It seems counterintuitive, but does GA count an event fired as a unique visit even if it's triggered from some place other than your website? Is so, there any way to trigger an event in the events section without it reporting to the unique visitor count?

    Read the article

  • Should I build a multi-threaded system that handles events from a game and sorts them, independently, into different threads based on priority?

    - by JonathonG
    Can I build a multi-threaded system that handles events from a game and sorts them, independently, into different threads based on priority, and is it a good idea? Here's more info: I am about to begin work on porting a mid-sized game from Flash/AS3 to Java so that I can continue development with multi-threading capabilities. Here's a small bit of background about the game: The game contains numerous asynchronous activities, such as "world updating" (the game environment is constantly changing based on a set of natural laws and forces), procedural generation of terrain, NPCs, quests, items, etc., and on top of that, the effects of all of the player's interactions with his environment are programmatically calculated in real time, based on a set of constantly changing "stats" and once again, natural laws and forces. All of these things going on at once, in an asynchronous manner, seem to lend themselves to multi-threading very well. My question is: Can I build some kind of central engine that handles the "stacking" of all of these events as they are triggered, and dynamically sorts them out amongst the available threads, and would it be a good idea? As an example: Essentially, every time something happens (IE, a magic missile being generated by a spell, or a bunch of plants need to grow to their next stage), instead of just processing that task right then and adding the new object(s) to a list of managed objects, send a reference to that event to a core "event handler" that throws it into a stack of all other currently queued events, which then sorts them out and orders them according to urgency, splits them between a number of available threads for as-fast-as-possible multithreaded execution.

    Read the article

  • Adding delegate with calendar access using Exchange Web Services?

    - by BryanG
    I have a set up where I need to add a delegate to various user calendars programmatically. Using a sample from MDSN, I've gotten as far as trying to add the delegate, but after the call to the service binding, I get nothing back...no success or fail....nothing. How I create the service binidng: // Initialize the service binding serviceBinding = new ExchangeServiceBinding(); serviceBinding.Credentials = new NetworkCredential(Properties.Settings.Default.UserName, Properties.Settings.Default.Password, Properties.Settings.Default.Domain); // A production application should call the autodiscover service to locate the service binding url serviceBinding.Url = Properties.Settings.Default.EWSUrlEndPoint; serviceBinding.RequestServerVersionValue = new RequestServerVersion(); serviceBinding.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2007_SP1; serviceBinding.AllowAutoRedirect = true; and the delegate addition: static void AddDelegate(string email) { // Create the request. AddDelegateType request = new AddDelegateType(); // Identify the agent's mailbox. request.Mailbox = new EmailAddressType(); request.Mailbox.EmailAddress = email; // add the exch_integration user as a delegate request.DelegateUsers = new DelegateUserType[1]; request.DelegateUsers[0] = new DelegateUserType(); request.DelegateUsers[0].UserId = new UserIdType(); request.DelegateUsers[0].UserId.PrimarySmtpAddress = "[email protected]"; // Specify the permissions that are granted to exch_integration request.DelegateUsers[0].DelegatePermissions = new DelegatePermissionsType(); request.DelegateUsers[0].DelegatePermissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevelType.Author; request.DelegateUsers[0].DelegatePermissions.CalendarFolderPermissionLevelSpecified = true; // Specify whether the agent recieves meeting requests. request.DeliverMeetingRequests = DeliverMeetingRequestsType.DelegatesAndSendInformationToMe; request.DeliverMeetingRequestsSpecified = true; try { // Send the request and get the response. AddDelegateResponseMessageType response = serviceBinding.AddDelegate(request); DelegateUserResponseMessageType[] responseMessages = response.ResponseMessages; // One DelegateUserResponseMessageType exists for each attempt to add a delegate user to an account. foreach (DelegateUserResponseMessageType user in responseMessages) { Console.WriteLine("Results of adding user: " + user.ResponseClass.ToString()); Console.WriteLine(user.DelegateUser.UserId.DisplayName); Console.WriteLine(user.DelegateUser.UserId.PrimarySmtpAddress); Console.WriteLine(user.DelegateUser.UserId.SID); } Console.ReadLine(); } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadLine(); } } The response nothing which must mean that the AddDelegate call isn't hitting the server properly, but I'm not sure. Thanks.

    Read the article

  • Why does this C# event handler not respond to this event in this Silverlight application?

    - by Edward Tanguay
    Can anyone tell me why the following code successfully executes this event: OnLoadingComplete(this, null); but never executes this event handler? void initialDataLoader_OnLoadingComplete(object obj, DataLoaderArgs args) CODE: using System; using System.Collections.Generic; using System.Linq; using System.Windows.Controls; using System.Diagnostics; namespace TestEvent22928 { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); DataLoader initialDataLoader = new DataLoader("initial"); initialDataLoader.RegisterText("test1", "http://test:111/testdata/test1.txt"); initialDataLoader.RegisterText("test2", "http://test:111/testdata/test2.txt"); initialDataLoader.BeginLoading(); initialDataLoader.OnLoadingComplete += new DataLoader.LoadingComplete(initialDataLoader_OnLoadingComplete); } void initialDataLoader_OnLoadingComplete(object obj, DataLoaderArgs args) { Debug.WriteLine("loading complete"); //WHY DOES EXECUTION NEVER GET HERE? } } public class DataManager { public DataLoader CreateDataloader(string dataloaderIdCode) { DataLoader dataLoader = new DataLoader(dataloaderIdCode); return dataLoader; } } public class DataLoader { public string IdCode { get; set; } public List<DataItem> DataItems { get; set; } public delegate void LoadingComplete(object obj, DataLoaderArgs args); public event LoadingComplete OnLoadingComplete = delegate { }; private int dataItemCurrentlyLoadingIndex; public DataLoader(string idCode) { IdCode = idCode; DataItems = new List<DataItem>(); dataItemCurrentlyLoadingIndex = -1; } public void RegisterText(string idCode, string absoluteSourceUrl) { DataItem dataItem = new DataItem { IdCode = idCode, AbsoluteSourceUrl = absoluteSourceUrl, Kind = DataItemKind.Text }; DataItems.Add(dataItem); } public void BeginLoading() { LoadNext(); } private void LoadNext() { dataItemCurrentlyLoadingIndex++; if (dataItemCurrentlyLoadingIndex < DataItems.Count()) { DataItem dataItem = DataItems[dataItemCurrentlyLoadingIndex]; Debug.WriteLine("loading " + dataItem.IdCode + "..."); LoadNext(); } else { OnLoadingComplete(this, null); //EXECUTION GETS HERE } } } public class DataItem { public string IdCode { get; set; } public string AbsoluteSourceUrl { get; set; } public DataItemKind Kind { get; set; } public object DataObject { get; set; } } public enum DataItemKind { Text, Image } public class DataLoaderArgs : EventArgs { public string Message { get; set; } public DataItem DataItem { get; set; } public DataLoaderArgs(string message, DataItem dataItem) { Message = message; DataItem = dataItem; } } }

    Read the article

  • DevExpress AspxGridView clientside SelectionChanged problem when using paged ObjectDataSource

    - by Constantin Baciu
    The context is as follows: One DexExpress AspxGridView with a server-side paging/filtering/sorting mechanism (using ObjectDataSource). I've been having problems with the filter mechanism ( see this stack ). Now, the problem I'm having is this: the client-side events get mangled between DataSource events. :O . Let me explain what happens: if I change the page (or sort/filter for that matter), then, select one row from the grid, the client-side SelectionChanged event fires well. If I change the page (or sort/filter), the event doesn't fire anymore. Instead, on the server side, I get a "The method or operation is not implemented" exception with the following stack-trace: at DevExpress.Web.Data.WebDataProviderBase.GetListSouceRowValue(Int32 listSourceRowIndex, String fieldName) at DevExpress.Web.Data.WebDataProxy.GetListSourceRowValue(Int32 listSourceRowIndex, String fieldName) at DevExpress.Web.Data.WebDataProxy.GetKeyValueCore(Int32 index, GetKeyValueCallback getKeyValue) at DevExpress.Web.Data.WebDataSelectionBase.GetSelectedValues(String[] fieldNames, Int32 visibleStartIndex, Int32 visibleRowCountOnPage) at DevExpress.Web.Data.WebDataProxy.GetSelectedValues(String[] fieldNames) at DevExpress.Web.ASPxGridView.ASPxGridView.FBSelectFieldValues(String[] args) at DevExpress.Web.ASPxGridView.ASPxGridView.GetCallbackResultCore() at DevExpress.Web.ASPxGridView.ASPxGridView.GetCallbackResult() at DevExpress.Web.ASPxClasses.ASPxWebControl.System.Web.UI.ICallbackEventHandler.GetCallbackResult() Am I doing something wrong? Any help will be much appreciated.

    Read the article

  • DevExpress AspxGridView clientside SelectionChanged problem when using paged ObjectDataSource

    - by Constantin Baciu
    The context is as follows: One DexExpress AspxGridView with a server-side paging/filtering/sorting mechanism (using ObjectDataSource). I've been having problems with the filter mechanism ( see this stack ). Now, the problem I'm having is this: the client-side events get mangled between DataSource events. :O . Let me explain what happens: if I change the page (or sort/filter for that matter), then, select one row from the grid, the client-side SelectionChanged event fires well. If I change the page (or sort/filter), the event doesn't fire anymore. Instead, on the server side, I get a "The method or operation is not implemented" exception with the following stack-trace: at DevExpress.Web.Data.WebDataProviderBase.GetListSouceRowValue(Int32 listSourceRowIndex, String fieldName) at DevExpress.Web.Data.WebDataProxy.GetListSourceRowValue(Int32 listSourceRowIndex, String fieldName) at DevExpress.Web.Data.WebDataProxy.GetKeyValueCore(Int32 index, GetKeyValueCallback getKeyValue) at DevExpress.Web.Data.WebDataSelectionBase.GetSelectedValues(String[] fieldNames, Int32 visibleStartIndex, Int32 visibleRowCountOnPage) at DevExpress.Web.Data.WebDataProxy.GetSelectedValues(String[] fieldNames) at DevExpress.Web.ASPxGridView.ASPxGridView.FBSelectFieldValues(String[] args) at DevExpress.Web.ASPxGridView.ASPxGridView.GetCallbackResultCore() at DevExpress.Web.ASPxGridView.ASPxGridView.GetCallbackResult() at DevExpress.Web.ASPxClasses.ASPxWebControl.System.Web.UI.ICallbackEventHandler.GetCallbackResult() Am I doing something wrong? Any help will be much appreciated.

    Read the article

  • Should an Event that has no arguments define its own custom EventArgs or simply use System.EventArgs

    - by Mike Rosenblum
    I have an event that is currently defined with no event arguments. That is, the EventArgs it sends is EventArgs.Empty. In this case, it is simplest to declare my Event handler as: EventHandler<System.EventArgs> MyCustomEvent; I do not plan on adding any event arguments to this event, but it is possible that any code could need to change in the future. Therefore, I am leaning towards having all my events always create an empty event args type that inheretis from System.EventArgs, even if there are no event args currently needed. Something like this: public class MyCustomEventArgs : EventArgs { } And then my event definition becomes the following: EventHandler<MyCustomEventArgs> MyCustomEvent; So my question is this: is it better to define my own MyCustomEventArgs, even if it does not add anything beyond inheriting from System.EventArgs, so that event arguments could be added in the future more easily? Or is it better to explicitly define my event as returning System.EventArgs, so that it is clearer to the user that there are no extra event args? I am leaning towards creating custom event arguments for all my events, even if the event arguments are empty. But I was wondering if others thought that making it clearer to the user that the event arguments are empty would be better? Much thanks in advance, Mike

    Read the article

  • Can WPF based ActiveX control use Reg-Free-COM

    - by embnut
    I have a WPF based ActiveX control (COM interop). I am able to use it correctly by registering the control. When I tried to Reg-Free-COM (using manifest files) the control seems to be activated, but the events (such as mouse click, RequestBringIntoView etc) dont respond. Interestingly, Double click and tab key works. I read in the this article http://blogs.msdn.com/karstenj/archive/2006/10/09/activex-wpf-gadget.aspx that " ... These upsides come with a price: the ActiveX control must be registered in the registry, which requires some kind of installation such as an .msi. The default gadget installation process cannot install ActiveX. The ActiveX control can't be access via reg-free COM. ..." Has anybody had a similar experience? Can anyone explain what is going on? Additional details: When the control is activated after it has been registered it appears as part of the COM client's UI. The control does not receive focus, its elements receive it. When using reg-free-com the control does not load correctly. 1) The control receives focus instead of its sub elements 2) The control has areas that are black instead of the windows default color 3) when I tab in and out of the control or double click it, it's subelements receive focus, the control starts receiving events and the black areas are replaced by the correct color

    Read the article

  • Weak event handler model for use with lambdas

    - by Benjol
    OK, so this is more of an answer than a question, but after asking this question, and pulling together the various bits from Dustin Campbell, Egor, and also one last tip from the 'IObservable/Rx/Reactive framework', I think I've worked out a workable solution for this particular problem. It may be completely superseded by IObservable/Rx/Reactive framework, but only experience will show that. I've deliberately created a new question, to give me space to explain how I got to this solution, as it may not be immediately obvious. There are many related questions, most telling you you can't use inline lambdas if you want to be able to detach them later: Weak events in .Net? Unhooking events with lambdas in C# Can using lambdas as event handlers cause a memory leak? How to unsubscribe from an event which uses a lambda expression? Unsubscribe anonymous method in C# And it is true that if YOU want to be able to detach them later, you need to keep a reference to your lambda. However, if you just want the event handler to detach itself when your subscriber falls out of scope, this answer is for you.

    Read the article

  • event flow in action script 3

    - by Shay
    i try to dispatch a custom event from some component on the stage and i register other component to listen to it but the other component doesn't get the event here is my code what do i miss public class Main extends MovieClip //main document class { var compSource:Game; var compMenu:Menu; public function Main() { compSource = new Game; compMenu = new Menu(); var mc:MovieClip = new MovieClip(); addChild(mc); mc.addChild(compSource); // the source of the event - event dispatch when clicked btn mc.addChild(compMenu); //in init of that Movie clip it add listener to the compSource events } } public class Game extends MovieClip { public function Game() { btn.addEventListener(MouseEvent.CLICK, onFinishGame); } private function onFinishGame(e:MouseEvent):void { var score:Number = Math.random() * 100 + 1; dispatchEvent(new ScoreChanged(score)); } } public class Menu extends MovieClip { //TextField score public function Menu() { addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event):void { removeEventListener(Event.ADDED_TO_STAGE, init); //on init add listener to event ScoreChanged addEventListener(ScoreChanged.SCORE_GAIN, updateScore); } public function updateScore(e:ScoreChanged):void { //it never gets here! tScore.text = String(e._score); } } public class ScoreChanged extends Event { public static const SCORE_GAIN:String = "SCORE_GAIN"; public var _score:Number; public function ScoreChanged( score:Number ) { trace("new score"); super( SCORE_GAIN, true); _score = score; } } I don't want to write in Main compSource.addEventListener(ScoreChanged.SCORE_GAIN, compMenu.updateScore); cause i dont want the the compSource will need to know about compMenu its compMenu responsibility to know to what events it needs to listen.... any suggestions? Thanks!

    Read the article

  • SWT: problems with clicking button after using setEnabled() on Linux

    - by Laimoncijus
    Hi, I have a strange case with SWT and Button after using setEnabled() - seems if I disable and enable button at least once - I cannot properly click with mouse on it anymore... Already minify code to very basic: import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class TestButton { public TestButton() { Display display = new Display(); Shell shell = new Shell(display); GridLayout mainLayout = new GridLayout(); shell.setLayout(mainLayout); shell.setSize(100, 100); Button testButton = new Button(shell, SWT.PUSH); testButton.addSelectionListener(new TestClickListener()); testButton.setText("Click me!"); //testButton.setEnabled(false); //testButton.setEnabled(true); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } class TestClickListener implements SelectionListener { @Override public void widgetDefaultSelected(SelectionEvent e) { } @Override public void widgetSelected(SelectionEvent e) { System.out.println("Click!"); } } public static void main(String[] args) { new TestButton(); } } When I keep these 2 lines commented out - I can properly click on a button and always get "Click!" logged, but if I uncomment them - then I can't click on button properly with mouse anymore - button visually seems to be clicked, but nothing is logged... Am I doing something wrong here? Or maybe it's some kind of bug on Linux platform? Because on Mac running the same code I never experienced such problems... Thanks for any hint! P.S. Running code on Ubuntu 9.10, Gnome + Compiz, Sun Java 1.6.0.16

    Read the article

  • C#: Need one of my classes to trigger an event in another class to update a text box

    - by Matt
    Total n00b to C# and events although I have been programming for a while. I have a class containing a text box. This class creates an instance of a communication manager class that is receiving frames from the Serial Port. I have this all working fine. Every time a frame is received and its data extracted, I want a method to run in my class with the text box in order to append this frame data to the text box. So, without posting all of my code I have my form class... public partial class Form1 : Form { CommManager comm; public Form1() { InitializeComponent(); comm = new CommManager(); } private void updateTextBox() { //get new values and update textbox } . . . and I have my CommManager class class CommManager { //here we manage the comms, recieve the data and parse the frame } SO... essentially, when I parse that frame, I need the updateTextBox method from the form class to run. I'm guessing this is possible with events but I can't seem to get it to work. I tried adding an event handler in the form class after creating the instance of CommManager as below... comm = new CommManager(); comm.framePopulated += new EventHandler(updateTextBox); ...but I must be doing this wrong as the compiler doesn't like it... Any ideas?!

    Read the article

  • ASP.Net event only being raised every other time?

    - by eftpotrm
    I have an ASP.Net web user control which represents a single entry in a list. To allow users to reorder the items, each item has buttons to move the item up or down the list. Clicking on one of these raises an event to the parent page, which then shuffles the items in the placeholder control. Code fragments from the list entry: Public Event UpClicked As System.EventHandler Protected Sub btnUp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUp.Click RaiseEvent UpClicked(Me, New EventArgs()) End Sub And the parent container: rem (within the code to add an individual item to the placeholder) AddHandler l_oItem.UpClicked, AddressOf UpClicked Protected Sub UpClicked(ByVal sender As Object, ByVal e As EventArgs) MoveItem(DirectCast(sender, ScriptListItem), -1) End Sub It originally looked in testing like every other time the value for sender (verified by its properties) that reaches UpClicked is of an adjacent ListItem, not the one I've just clicked on - the first click is always wrong, then the second for the correct control. At present, testing appears to show that the button's click event is just being ignored every other time through. Breakpoints on the click events within the control simply aren't being hit, though the events are definitely being established. Why?

    Read the article

  • How to defer execution of an Event on each item in a collection until iteration of collection is com

    - by Metro Smurf
    Of Note: This is more of a curiosity question than anything else. Given a List<Window> where each window has an event attached to the Close Event which removes the window from the collection, how could you use delegates / events to defer the execution of the Close Event until the collection has been iterated? For example: public class Foo { private List<Window> OpenedWindows { get; set; } public Foo() { OpenedWindows = new List<Window>(); } public void AddWindow( Window win ) { win.Closed += OnWindowClosed; OpenedWindows.Add( win ); } void OnWindowClosed( object sender, EventArgs e ) { var win = sender as Window; if( win != null ) { OpenedWindows.Remove( win ); } } void CloseAllWindows() { // obviously will not work because we can't // remove items as we iterate the collection // (the close event removes the window from the collection) OpenedWindows.ForEach( x => x.Close() ); // works fine, but would like to know how to do // this with delegates / events. while( OpenedWindows.Any() ) { OpenedWindows[0].Close(); } } } Specifically, within the CloseAllWindows() method, how could you iterate the collection to call the close event, but defer the event being raised until the collection has been completely iterated?

    Read the article

  • jQuery trigger custom event synchronously?

    - by Miguel Angelo
    I am using the jQuery trigger method to call an event... but it behaves inconsistently. Sometimes it call the event, sometimes it does not. <a href="#" onclick=" $(this).trigger('custom-event'); window.location.href = 'url'; return false; ">text</a> The custom-event has lots of listeners added to it. It is as if the trigger method is not synchronous, allowing the window.location.href be changed before executing the events. And when window.location.href is changed a navigation occurs, interrupting everything. How can I trigger events synchronously? Using jQuery 1.8.1. Thanks! EDIT I have found that the event, when called has a stack trace like this: jQuery.fx.tick (jquery-1.8.1.js:9021) tick (jquery-1.8.1.js:8499) jQuery.Callbacks.self.fireWith (jquery-1.8.1.js:1082) jQuery.Callbacks.fire (jquery-1.8.1.js:974) jQuery.speed.opt.complete (jquery-1.8.1.js:8991) $.customEvent (myfile.js:28) This proves that jQuery trigger method is asynchronous. Oohhh my... =\

    Read the article

  • How to create custom MouseEvent.CLICK event in AS3 (pass parameters to function)?

    - by fromvega
    Hello, This question doesn't relate only to MouseEvent.CLICK event type but to all event types that already exist in AS3. I read a lot about custom events but until now I couldn't figure it out how to do what I want to do. I'm going to try to explain, I hope you understand: Here is a illustration of my situation: for(var i:Number; i < 10; i++){ var someVar = i; myClips[i].addEventListener(MouseEvent.CLICK, doSomething); } function doSomething(e:MouseEvent){ /* */ } But I want to be able to pass someVar as a parameter to doSomething. So I tried this: for(var i:Number; i < 10; i++){ var someVar = i; myClips[i].addEventListener(MouseEvent.CLICK, function(){ doSomething(someVar); }); } function doSomething(index){ trace(index); } This kind of works but not as I expect. Due to the function closures, when the MouseEvent.CLICK events are actually fired the for loop is already over and someVar is holding the last value, the number 9 in the example. So every click in each movie clip will call doSomething passing 9 as the parameter. And it's not what I want. I thought that creating a custom event should work, but then I couldn't find a way to fire a custom event when the MouseEvent.CLICK event is fired and pass the parameter to it. Now I don't know if it is the right answer. What should I do and how?

    Read the article

  • Why is C# winforms application not working without VS.NET installed?

    - by Shane
    Hi folks, I have a winforms c# app that has an embedded webbrowser control inside it generated through VS.NET 2008. We sink events by inheriting our events class from HTMLDocumentEvents2. public class IEHTMLDocumentEvents : mshtml.HTMLDocumentEvents2 { public bool onclick(mshtml.IHTMLEventObj pEvtObj) { // Clicking on an input (checkbox, radio, button, image) if (pEvtObj.srcElement.tagName == "INPUT") { // The following will result in a null pointer without VS.NET installed HTMLInputElementClass input = pEvtObj.srcElement as HTMLInputElementClass; } } } The code above works fine when clicking on elements in the webbrowser control on our dev machines with VS.NET installed. However it fails to cast the pEvtObj.srcElement when VS.NET is not installed. This immediately starts working when we install the most basic VS.NET with C# that you can. To note: The rest of the c# app works fine, and you can browser the web through the control fine as well, just that the events like the above 'onclick' can't be handled properly. I thought it would be a DLL version loaded issue but doing a diff of the files loaded indicates only minor differences. 1c1 < Process: C# App without VS.NET installed --- > Process: C# App with VS.NET 2008 installed 18d17 < C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\CustomMarshalers\e148983beeb0f30918b0564849a16456\CustomMarshalers.ni.dll CustomMarshalers.ni.dll Microsoft .NET Framework Custom Marshalers Microsoft Corporation 2.0.50727.3053 36d34 < C:\Documents and Settings\XpHome\Local Settings\History\History.IE5\index.dat index.dat 37a36 > C:\Documents and Settings\XpHome\Local Settings\History\History.IE5\index.dat index.dat 44,45c43,44 < C:\Program Files\<hidden>\<hidden>\Microsoft.mshtml.dll Microsoft.mshtml.dll 7.0.3300.1 < C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\Microsoft.VisualBas#\5b3d048d8c003d743ea5e72caf07773a\Microsoft.VisualBasic.ni.dll Microsoft.VisualBasic.ni.dll Visual Basic Runtime Library Microsoft Corporation 8.0.50727.3053 --- > C:\WINDOWS\assembly\GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a\Microsoft.mshtml.dll Microsoft.mshtml.dll 7.0.3300.1 > C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualBasic\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.dll Microsoft.VisualBasic.dll Visual Basic Runtime Library Microsoft Corporation 8.0.50727.3053 50,52c49,51 < c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll mscorjit.dll Microsoft .NET Runtime Just-In-Time Compiler Microsoft Corporation 2.0.50727.3053 < C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\9adb89fa22fd5b4ce433b5aca7fb1b07\mscorlib.ni.dll mscorlib.ni.dll Microsoft Common Language Runtime Class Library Microsoft Corporation 2.0.50727.3053 < c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll mscorwks.dll Microsoft .NET Runtime Common Language Runtime - WorkStation Microsoft Corporation 2.0.50727.3053 --- > c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll mscorjit.dll Microsoft .NET Runtime Just-In-Time Compiler Microsoft Corporation 2.0.50727.3082 > C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\7124a40b9998f7b63c86bd1a2125ce26\mscorlib.ni.dll mscorlib.ni.dll Microsoft Common Language Runtime Class Library Microsoft Corporation 2.0.50727.3603 > c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll mscorwks.dll Microsoft .NET Runtime Common Language Runtime - WorkStation Microsoft Corporation 2.0.50727.3603 94,98c93,97 < C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Configuration\cb4cb21d14767292e079366a5d3d76cd\System.Configuration.ni.dll System.Configuration.ni.dll System.Configuration.dll Microsoft Corporation 2.0.50727.3053 < C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Drawing\6978f2e90f13bc720d57fa6895c911e2\System.Drawing.ni.dll System.Drawing.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3053 < C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System\aa7926460a336408c8041330ad90929d\System.ni.dll System.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3053 < C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Windows.Forms\9a254c455892c02355ab0ab0f0727c5b\System.Windows.Forms.ni.dll System.Windows.Forms.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3053 < C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Xml\36f3953f24d4f0b767bf172331ad6f3e\System.Xml.ni.dll System.Xml.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3053 --- > C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll System.Configuration.dll System.Configuration.dll Microsoft Corporation 2.0.50727.3053 > C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Drawing\abb2ac7e08bee026f857d8fa36f9fe6f\System.Drawing.ni.dll System.Drawing.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3053 > C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System\3de5bd01124463d7862bd173af90bc83\System.ni.dll System.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3053 > C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Windows.Forms\d2ea8d76f015817db1607075812b555f\System.Windows.Forms.ni.dll System.Windows.Forms.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3053 > C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Xml\5913d3f81e77194ec833991b1047a532\System.Xml.ni.dll System.Xml.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3082

    Read the article

  • Using WeakReference to resolve issue with .NET unregistered event handlers causing memory leaks.

    - by Eric
    The problem: Registered event handlers create a reference from the event to the event handler's instance. If that instance fails to unregister the event handler (via Dispose, presumably), then the instance memory will not be freed by the garbage collector. Example: class Foo { public event Action AnEvent; public void DoEvent() { if (AnEvent != null) AnEvent(); } } class Bar { public Bar(Foo l) { l.AnEvent += l_AnEvent; } void l_AnEvent() { } } If I instantiate a Foo, and pass this to a new Bar constructor, then let go of the Bar object, it will not be freed by the garbage collector because of the AnEvent registration. I consider this a memory leak, and seems just like my old C++ days. I can, of course, make Bar IDisposable, unregister the event in the Dispose() method, and make sure to call Dispose() on instances of it, but why should I have to do this? I first question why events are implemented with strong references? Why not use weak references? An event is used to abstractly notify an object of changes in another object. It seems to me that if the event handler's instance is no longer in use (i.e., there are no non-event references to the object), then any events that it is registered with should automatically be unregistered. What am I missing? I have looked at WeakEventManager. Wow, what a pain. Not only is it very difficult to use, but its documentation is inadequate (see http://msdn.microsoft.com/en-us/library/system.windows.weakeventmanager.aspx -- noticing the "Notes to Inheritors" section that has 6 vaguely described bullets). I have seen other discussions in various places, but nothing I felt I could use. I propose a simpler solution based on WeakReference, as described here. My question is: Does this not meet the requirements with significantly less complexity? To use the solution, the above code is modified as follows: class Foo { public WeakReferenceEvent AnEvent = new WeakReferenceEvent(); internal void DoEvent() { AnEvent.Invoke(); } } class Bar { public Bar(Foo l) { l.AnEvent += l_AnEvent; } void l_AnEvent() { } } Notice two things: 1. The Foo class is modified in two ways: The event is replaced with an instance of WeakReferenceEvent, shown below; and the invocation of the event is changed. 2. The Bar class is UNCHANGED. No need to subclass WeakEventManager, implement IWeakEventListener, etc. OK, so on to the implementation of WeakReferenceEvent. This is shown here. Note that it uses the generic WeakReference that I borrowed from here: http://damieng.com/blog/2006/08/01/implementingweakreferencet I had to add Equals() and GetHashCode() to his class, which I include below for reference. class WeakReferenceEvent { public static WeakReferenceEvent operator +(WeakReferenceEvent wre, Action handler) { wre._delegates.Add(new WeakReference<Action>(handler)); return wre; } public static WeakReferenceEvent operator -(WeakReferenceEvent wre, Action handler) { foreach (var del in wre._delegates) if (del.Target == handler) { wre._delegates.Remove(del); return wre; } return wre; } HashSet<WeakReference<Action>> _delegates = new HashSet<WeakReference<Action>>(); internal void Invoke() { HashSet<WeakReference<Action>> toRemove = null; foreach (var del in _delegates) { if (del.IsAlive) del.Target(); else { if (toRemove == null) toRemove = new HashSet<WeakReference<Action>>(); toRemove.Add(del); } } if (toRemove != null) foreach (var del in toRemove) _delegates.Remove(del); } } public class WeakReference<T> : IDisposable { private GCHandle handle; private bool trackResurrection; public WeakReference(T target) : this(target, false) { } public WeakReference(T target, bool trackResurrection) { this.trackResurrection = trackResurrection; this.Target = target; } ~WeakReference() { Dispose(); } public void Dispose() { handle.Free(); GC.SuppressFinalize(this); } public virtual bool IsAlive { get { return (handle.Target != null); } } public virtual bool TrackResurrection { get { return this.trackResurrection; } } public virtual T Target { get { object o = handle.Target; if ((o == null) || (!(o is T))) return default(T); else return (T)o; } set { handle = GCHandle.Alloc(value, this.trackResurrection ? GCHandleType.WeakTrackResurrection : GCHandleType.Weak); } } public override bool Equals(object obj) { var other = obj as WeakReference<T>; return other != null && Target.Equals(other.Target); } public override int GetHashCode() { return Target.GetHashCode(); } } It's functionality is trivial. I override operator + and - to get the += and -= syntactic sugar matching events. These create WeakReferences to the Action delegate. This allows the garbage collector to free the event target object (Bar in this example) when nobody else is holding on to it. In the Invoke() method, simply run through the weak references and call their Target Action. If any dead (i.e., garbage collected) references are found, remove them from the list. Of course, this only works with delegates of type Action. I tried making this generic, but ran into the missing where T : delegate in C#! As an alternative, simply modify class WeakReferenceEvent to be a WeakReferenceEvent, and replace the Action with Action. Fix the compiler errors and you have a class that can be used like so: class Foo { public WeakReferenceEvent<int> AnEvent = new WeakReferenceEvent<int>(); internal void DoEvent() { AnEvent.Invoke(5); } } Hopefully this will help someone else when they run into the mystery .NET event memory leak!

    Read the article

< Previous Page | 74 75 76 77 78 79 80 81 82 83 84 85  | Next Page >