Search Results

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

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

  • Watching a variable for changes without polling.

    - by milkfilk
    I'm using a framework called Processing which is basically a Java applet. It has the ability to do key events because Applet can. You can also roll your own callbacks of sorts into the parent. I'm not doing that right now and maybe that's the solution. For now, I'm looking for a more POJO solution. So I wrote some examples to illustrate my question. Please ignore using key events on the command line (console). Certainly this would be a very clean solution but it's not possible on the command line and my actual app isn't a command line app. In fact, a key event would be a good solution for me but I'm trying to understand events and polling beyond just keyboard specific problems. Both these examples flip a boolean. When the boolean flips, I want to fire something once. I could wrap the boolean in an Object so if the Object changes, I could fire an event too. I just don't want to poll with an if() statement unnecessarily. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /* * Example of checking a variable for changes. * Uses dumb if() and polls continuously. */ public class NotAvoidingPolling { public static void main(String[] args) { boolean typedA = false; String input = ""; System.out.println("Type 'a' please."); while (true) { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); try { input = br.readLine(); } catch (IOException ioException) { System.out.println("IO Error."); System.exit(1); } // contrived state change logic if (input.equals("a")) { typedA = true; } else { typedA = false; } // problem: this is polling. if (typedA) System.out.println("Typed 'a'."); } } } Running this outputs: Type 'a' please. a Typed 'a'. On some forums people suggested using an Observer. And although this decouples the event handler from class being observed, I still have an if() on a forever loop. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Observable; import java.util.Observer; /* * Example of checking a variable for changes. * This uses an observer to decouple the handler feedback * out of the main() but still is polling. */ public class ObserverStillPolling { boolean typedA = false; public static void main(String[] args) { // this ObserverStillPolling o = new ObserverStillPolling(); final MyEvent myEvent = new MyEvent(o); final MyHandler myHandler = new MyHandler(); myEvent.addObserver(myHandler); // subscribe // watch for event forever Thread thread = new Thread(myEvent); thread.start(); System.out.println("Type 'a' please."); String input = ""; while (true) { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); try { input = br.readLine(); } catch (IOException ioException) { System.out.println("IO Error."); System.exit(1); } // contrived state change logic // but it's decoupled now because there's no handler here. if (input.equals("a")) { o.typedA = true; } } } } class MyEvent extends Observable implements Runnable { // boolean typedA; ObserverStillPolling o; public MyEvent(ObserverStillPolling o) { this.o = o; } public void run() { // watch the main forever while (true) { // event fire if (this.o.typedA) { setChanged(); // in reality, you'd pass something more useful notifyObservers("You just typed 'a'."); // reset this.o.typedA = false; } } } } class MyHandler implements Observer { public void update(Observable obj, Object arg) { // handle event if (arg instanceof String) { System.out.println("We received:" + (String) arg); } } } Running this outputs: Type 'a' please. a We received:You just typed 'a'. I'd be ok if the if() was a NOOP on the CPU. But it's really comparing every pass. I see real CPU load. This is as bad as polling. I can maybe throttle it back with a sleep or compare the elapsed time since last update but this is not event driven. It's just less polling. So how can I do this smarter? How can I watch a POJO for changes without polling? In C# there seems to be something interesting called properties. I'm not a C# guy so maybe this isn't as magical as I think. private void SendPropertyChanging(string property) { if (this.PropertyChanging != null) { this.PropertyChanging(this, new PropertyChangingEventArgs(property)); } }

    Read the article

  • Is there a better way to avoid an infinite loop using winforms?

    - by Hamish Grubijan
    I am using .Net 3.5 for now. Right now I am using a using trick to disable and enable events around certain sections of code. The user can change either days, hours, minutes or total minutes, and that should not cause an infinite cascade of events (e.g. minutes changing total, total changing minutes, etc.) While the code does what I want, there might be a better / more straight-forward way. Do you know of any? For brawny points: This control will be used by multiple teams - I do not want to make it embarrassing. I suspect that I do not need to reinvent the wheel when defining hours in a day, days in week, etc. Some other standard .Net library out there must have it. Any other remarks regarding code? This using (EventHacker.DisableEvents(this)) business - that must be a common pattern in .Net ... changing the setting temporarily. What is the name of it? I'd like to be able to refer to it in a comment and also read up more on current implementations. In the general case not only a handle to the thing being changed needs to be remembered, but also the previous state (in this case previous state does not matter - events are turned on and off unconditionally). Then there is also a possibility of multi-threaded hacking. One could also utilize generics to make the code arguably cleaner. Figuring all this out can lead to a multi-page blog post. I'd be happy to hear some of the answers. P.S. Does it seem like I suffer from obsessive compulsive disorder? Some people like to get things finished and move on; I like to keep them open ... there is always a better way. // Corresponding Designer class is omitted. using System; using System.Windows.Forms; namespace XYZ // Real name masked { interface IEventHackable { void EnableEvents(); void DisableEvents(); } public partial class PollingIntervalGroupBox : GroupBox, IEventHackable { private const int DAYS_IN_WEEK = 7; private const int MINUTES_IN_HOUR = 60; private const int HOURS_IN_DAY = 24; private const int MINUTES_IN_DAY = MINUTES_IN_HOUR * HOURS_IN_DAY; private const int MAX_TOTAL_DAYS = 100; private static readonly decimal MIN_TOTAL_NUM_MINUTES = 1; // Anything faster than once per minute can bog down our servers. private static readonly decimal MAX_TOTAL_NUM_MINUTES = (MAX_TOTAL_DAYS * MINUTES_IN_DAY) - 1; // 99 days should be plenty. // The value above was chosen so to not cause an overflow exception. // Watch out for it - numericUpDownControls each have a MaximumValue setting. public PollingIntervalGroupBox() { InitializeComponent(); InitializeComponentCustom(); } private void InitializeComponentCustom() { this.m_upDownDays.Maximum = MAX_TOTAL_DAYS - 1; this.m_upDownHours.Maximum = HOURS_IN_DAY - 1; this.m_upDownMinutes.Maximum = MINUTES_IN_HOUR - 1; this.m_upDownTotalMinutes.Maximum = MAX_TOTAL_NUM_MINUTES; this.m_upDownTotalMinutes.Minimum = MIN_TOTAL_NUM_MINUTES; } private void m_upDownTotalMinutes_ValueChanged(object sender, EventArgs e) { setTotalMinutes(this.m_upDownTotalMinutes.Value); } private void m_upDownDays_ValueChanged(object sender, EventArgs e) { updateTotalMinutes(); } private void m_upDownHours_ValueChanged(object sender, EventArgs e) { updateTotalMinutes(); } private void m_upDownMinutes_ValueChanged(object sender, EventArgs e) { updateTotalMinutes(); } private void updateTotalMinutes() { this.setTotalMinutes( MINUTES_IN_DAY * m_upDownDays.Value + MINUTES_IN_HOUR * m_upDownHours.Value + m_upDownMinutes.Value); } public decimal TotalMinutes { get { return m_upDownTotalMinutes.Value; } set { m_upDownTotalMinutes.Value = value; } } public decimal TotalHours { set { setTotalMinutes(value * MINUTES_IN_HOUR); } } public decimal TotalDays { set { setTotalMinutes(value * MINUTES_IN_DAY); } } public decimal TotalWeeks { set { setTotalMinutes(value * DAYS_IN_WEEK * MINUTES_IN_DAY); } } private void setTotalMinutes(decimal nTotalMinutes) { if (nTotalMinutes < MIN_TOTAL_NUM_MINUTES) { setTotalMinutes(MIN_TOTAL_NUM_MINUTES); return; // Must be carefull with recursion. } if (nTotalMinutes > MAX_TOTAL_NUM_MINUTES) { setTotalMinutes(MAX_TOTAL_NUM_MINUTES); return; // Must be carefull with recursion. } using (EventHacker.DisableEvents(this)) { // First set the total minutes this.m_upDownTotalMinutes.Value = nTotalMinutes; // Then set the rest this.m_upDownDays.Value = (int)(nTotalMinutes / MINUTES_IN_DAY); nTotalMinutes = nTotalMinutes % MINUTES_IN_DAY; // variable reuse. this.m_upDownHours.Value = (int)(nTotalMinutes / MINUTES_IN_HOUR); nTotalMinutes = nTotalMinutes % MINUTES_IN_HOUR; this.m_upDownMinutes.Value = nTotalMinutes; } } // Event magic public void EnableEvents() { this.m_upDownTotalMinutes.ValueChanged += this.m_upDownTotalMinutes_ValueChanged; this.m_upDownDays.ValueChanged += this.m_upDownDays_ValueChanged; this.m_upDownHours.ValueChanged += this.m_upDownHours_ValueChanged; this.m_upDownMinutes.ValueChanged += this.m_upDownMinutes_ValueChanged; } public void DisableEvents() { this.m_upDownTotalMinutes.ValueChanged -= this.m_upDownTotalMinutes_ValueChanged; this.m_upDownDays.ValueChanged -= this.m_upDownDays_ValueChanged; this.m_upDownHours.ValueChanged -= this.m_upDownHours_ValueChanged; this.m_upDownMinutes.ValueChanged -= this.m_upDownMinutes_ValueChanged; } // We give as little info as possible to the 'hacker'. private sealed class EventHacker : IDisposable { IEventHackable _hackableHandle; public static IDisposable DisableEvents(IEventHackable hackableHandle) { return new EventHacker(hackableHandle); } public EventHacker(IEventHackable hackableHandle) { this._hackableHandle = hackableHandle; this._hackableHandle.DisableEvents(); } public void Dispose() { this._hackableHandle.EnableEvents(); } } } }

    Read the article

  • Exchange 2010: Receiving "You can't send a message on behalf of this user..." error when trying to configure delegate access

    - by Beaming Mel-Bin
    I am trying to give someone (John Doe) delegate access to another account (Jane Doe) in our test environment. However, I receive the following error from Exchange: *Subject:* Undeliverable: You have been designated as a delegate for Jane Dow *To:* Jane Dow Delivery has failed to these recipients or groups: John Doe You can't send a message on behalf of this user unless you have permission to do so. Please make sure you're sending on behalf of the correct sender, or request the necessary permission. If the problem continues, please contact your helpdesk. Diagnostic information for administrators: Generating server: /O=UNIONCO/OU=EXCHANGE ADMINISTRATIVE GROUP (FYD132341234)/CN=RECIPIENTS/CN=jdoe #MSEXCH:MSExchangeIS:/DC=local/DC=unionco:MAILBOX-1[578:0x000004DC:0x0000001D] #EX# Can someone help me troubleshoot this?

    Read the article

  • Analiytics: Can I set a goal on multiple events?

    - by David Parks
    We have a popup dialogue that requests users email address or facebook login. The page behind the popup loads, so a page view is counted. We want to measure: How many users ignored the popup completely How many users engaged the popup, but don't complete the process (we trigger an event when the user performs actions defined as "engaging") How many users completed the popup Bounce rates aren't telling because some users won't receive the popup. We are basically triggering events "PopupDisplayed" "PopupEngaged" and "PopupComplete", with labels to differentiate between email and facebook. But I don't think I can set goals to count "Users who received 'PopupDisplayed' AND 'PopupComplete'" events, so I can count how many users both saw the popup and completed it.

    Read the article

  • Script/ Macro in Excel, by clicking on a cell

    - by Noob Doob
    There's something I want to do in Excel 2010. Specifically, I want to be able to make the open sheet load data from a text file, by clicking -important- on a cell of the current open worksheet. So my specific needs are: If it is possible in some way, to start a macro/script by clicking on a cell. About the script/macro: What would be the preferable, by your opinion, way of implementation. And more specifically, how to automatically import the data needed, only by clicking, without having to continually specify the desirable .txt file each time, only 1 time at max, at start or by using a custom "initalization/configuration" file.

    Read the article

  • How may I monitor all gestures of the entire system

    - by Jiulong Zhao
    I can make a view to accept touch event and receive detailed gesture event like this: [self setAcceptsTouchEvents:YES]; // NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:self]; I can also receive global event by crate a monitor in this way: NSUInteger eventMasks = NSEventTypeBeginGesture | NSEventTypeEndGesture | NSEventMaskGesture; [NSEvent addGlobalMonitorForEventsMatchingMask:eventMasks handler:^(NSEvent *theevent) {//do something}]; But I can NOT get the detailed event from monitor by -touchesMatchingPhase How may I monitor all gestures of the entire system.

    Read the article

  • Excel 2010: dynamic update of drop down list based upon datasource validation worksheet changes

    - by hornetbzz
    I have one worksheet for setting up the data sources of multiple data validation lists. in other words, I'm using this worksheet to provide drop down lists to multiple other worksheets. I need to dynamically update all worksheets upon any of a single or several changes on the data source worksheet. I may understand this should come with event macro over the entire workbook. My question is how to achieve this keeping the "OFFSET" formula across the whole workbook ? Thx To support my question, I put the piece of code that I'm trying to get it working : Provided the following informations : I'm using such a formula for a pseudo dynamic update of the drop down lists, for example : =OFFSET(MyDataSourceSheet!$O$2;0;0;COUNTA(MyDataSourceSheet!O:O)-1) I looked into the pearson book event chapter but I'm too noob for this. I understand this macro and implemented it successfully as a test with the drop down list on the same worksheet as the data source. My point is that I don't know how to deploy this over a complete workbook. Macro related to the datasource worksheet : Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) ' Macro to update all worksheets with drop down list referenced upon ' this data source worksheet, base on ref names Dim cell As Range Dim isect As Range Dim vOldValue As Variant, vNewValue As Variant Dim dvLists(1 To 6) As String 'data validation area Dim OneValidationListName As Variant dvLists(1) = "mylist1" dvLists(2) = "mylist2" dvLists(3) = "mylist3" dvLists(4) = "mylist4" dvLists(5) = "mylist5" dvLists(6) = "mylist6" On Error GoTo errorHandler For Each OneValidationListName In dvLists 'Set isect = Application.Intersect(Target, ThisWorkbook.Names("STEP").RefersToRange) Set isect = Application.Intersect(Target, ThisWorkbook.Names(OneValidationListName).RefersToRange) ' If a change occured in the source data sheet If Not isect Is Nothing Then ' Prevent infinite loops Application.EnableEvents = False ' Get previous value of this cell With Target vNewValue = .Value Application.Undo vOldValue = .Value .Value = vNewValue End With ' LOCAL dropdown lists : For every cell with validation For Each cell In Me.UsedRange.SpecialCells(xlCellTypeAllValidation) With cell ' If it has list validation AND the validation formula matches AND the value is the old value If .Validation.Type = 3 And .Validation.Formula1 = "=" & OneValidationListName And .Value = vOldValue Then ' Debug ' MsgBox "Address: " & Target.Address ' Change the cell value cell.Value = vNewValue End If End With Next cell ' Call to other worksheets update macros Call Sheets(5).UpdateDropDownList(vOldValue, vNewValue) ' GoTo NowGetOut Application.EnableEvents = True End If Next OneValidationListName NowGetOut: Application.EnableEvents = True Exit Sub errorHandler: MsgBox "Err " & Err.Number & " : " & Err.Description Resume NowGetOut End Sub Macro UpdateDropDownList related to the destination worksheet : Sub UpdateDropDownList(Optional vOldValue As Variant, Optional vNewValue As Variant) ' Debug MsgBox "Received info for update : " & vNewValue ' For every cell with validation For Each cell In Me.UsedRange.SpecialCells(xlCellTypeAllValidation) With cell ' If it has list validation AND the validation formula matches AND the value is the old value ' If .Validation.Type = 3 And .Value = vOldValue Then If .Validation.Type = 3 And .Value = vOldValue Then ' Change the cell value cell.Value = vNewValue End If End With Next cell End Sub

    Read the article

  • Is there a way to see what shutdown the computer?

    - by Celeritas
    I had many programs opened and was typing a message in my web browser and suddenly a window asking me something popped up. I think I was in the middle of typing the word "for" but whatever button I hit seemed to be the confirmation to shutdown the computer. Is there a way to find which program caused this and prevent it in the future? I have a hunch it was JDownloaders fault. I'm using Windows 7.

    Read the article

  • How do I automatically copy data when attaching external storage?

    - by Iceking007
    If I am correct to assume that once I place a DVD/disk in my optical drive (or use a USB flash drive or external HDD for that matter; for arguments sake) that this action would in effect trigger an 'event' in Windows. I would like to use this 'triggered event' to enable an entire copy of that device. Example: if my optical H: reads a disk OR the user closes the tray OR ... then xcopy /S H: "F:\Copy of H"

    Read the article

  • Accept and Decline button missing in thunderbird when receiving an invitation

    - by Laurent Lugon
    I'm using Thunderbird 12.0.1 with the following add-ons for the calendar : Lightning 1.4 Provider for Google calendar 0.9 I'm working with Ubuntu 12.04 My problem is when I receive an event invitation from outlook or gmail, the mail is correctly identified by Thunderbird (I have the message "this message contains an invitation to an event"). In the pretty little box in the mail (the one which contains all the details), there is no "Accpet" or "Decline" button... I found on the Lightning forum that this bug was fixed in Lightning V.1.0b2 So my question is : why do I still have this bug ??? Best regards

    Read the article

  • Analytics - Total events divided by number of unique pages?

    - by GeekyAndUnique
    I am using Google Analytics events to track keywords on my articles - not necessarily the best system I know but there are too many for variables I can't easily change it right now - and I would like to be able to see how popular each keyword is by dividing the number of page views with a keyword by the number of unique pages. Is there a/what is the best way of doing this? EDIT FOR CLARITY I currently have a system set up where every time somebody loads an article an event is fired for each of the tags/keywords used, with the keyword being the label. I can currently view my view count for each of the keywords by looking at the total events for each label, however I would like to be able to see which keywords are the most popular by dividing the number of times the event has been fired by the the number of different pages it has been fired from.

    Read the article

  • Why the CLLocationManager delegate is not getting called in iPhone SDK 4.0 ???

    - by Biranchi
    Hi, This is the code that I have in my AppDelegate Class - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { CLLocationManager *locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.distanceFilter = 1000; // 1 Km locationManager.desiredAccuracy = kCLLocationAccuracyKilometer; [locationManager startUpdatingLocation]; } And this is the delegate method i have in my AppDelegate Class //This is the delegate method for CoreLocation - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { //printf("AppDelegate latitude %+.6f, longitude %+.6f\n", newLocation.coordinate.latitude, newLocation.coordinate.longitude); } Its working in 3.0, 3.1, 3.1.3 , but its not working in 4.0 simulator and device both. What is the reason ?? I am getting frustrated ...... Thanks....

    Read the article

  • BlackBerry - KeyListener with global scope

    - by Abs
    Hello all, I am new to BlackBerry App development. I want to be able to listen for keypress events whenever the BlackBerry (8900 in my case) is on and on all screens is this possible? If so, it would be great for someone to direct me in the right direction. I am already having a look at Interface KeyListener. import net.rim.device.api.system.*; Thanks all

    Read the article

  • Why not systematically attach event in WPF instead of using delegate ?

    - by user310291
    For a button to handle event, we can add a delegate to the click property of the button: this.button1.Click += new System.EventHandler(this.button1_Click); But in WPF contrary to Winform, you can also attach a handler http://msdn.microsoft.com/en-us/magazine/cc785480.aspx So why not do so for the button ? Is performance better in first case maybe ? Update: I mean this Attached Events In order to enable elements to handle events that are declared in a different element, WPF supports something called attached events. Attached events are routed events that support a hookup in XAML on elements other than the type on which the event is declared. For example, if you want the Grid element to listen for a Button.Click event to bubble past, you would simply hook it up like the following: <Grid Button.Click="myButton_Click"> <Button Name="myButton" >Click Me</Button> </Grid> The resulting code in the compile-time-generated partial class now looks like this: #line 5 "..\..\Window1.xaml" ((System.Windows.Controls.Grid)(target)).AddHandler( System.Windows.Controls.Primitives.ButtonBase.ClickEvent, new System.Windows.RoutedEventHandler(this.myButton_Click));

    Read the article

  • Responding to the onmousemove event outside of the browser window in IE

    - by Matthew Lock
    In Internet Explorer 7 body onmousemove or document.onmousemove events only seem to fire while the mouse is inside the browser window, not when it's outside. Yet in Firefox the onmousemove event is called correctly when I move outside of the browser window. How can I setup an event to be called outside of the browser window in IE? Google Maps does this in IE. If you hold the mouse button down and move the mouse outside of the browser window you can see that the map still moves.

    Read the article

  • While Mouse press event. Prototype JS or Javascript

    - by nahum
    Hi, I would like to know if someone knows how to make a function repeat over and over while the mouse is press, I don't know how to make it work. I know in prototype you can take events like $('id').observe("click",function(event){}) $('id').observe("leave",function(event){}) $('id').observe("change",function(event){}) //etc... but is something like $('id').observe("whilemousepress",function(event){}) :P //I know there is not any event in javascript but I would like to emulate. thanks...

    Read the article

  • epoll_wait: maxevents

    - by someguy
    int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout); I'm a little confused about the maxevents parameter. Let's say I want to write a server that can handle up to 10k connections. Would I define maxevents as 10000 then, or should it be be lower for some reason?

    Read the article

  • Event on Item Marked as Read in Outlook - Delphi COM Add-in

    - by Tao
    I have a Delphi COM Add-in for Outlook (2000-2007) and am trying to find a way to register an event when an MailItem in Outlook is marked as read. I want to add an additional property to the item as/just after it is marked as read. Does anyone have any idea how to do this using the Outlook Object Model? I am also using Add-In-Express components to help get to additional properties events.

    Read the article

  • What is the best way to handle multiple actions?

    - by Schotime
    Like most web applications you have a method that gets called when you log in. There are a few things that may need to get done when logged in and over time this may increase. eg. logging, welcome emails, maintenance. Should events be used to do this or is there a better way?? I'm using C# and ASP.net MVC.

    Read the article

  • IPhone SDK handling calls

    - by Yasir Hussain
    Is there any way to handle call events in IPhone? i.e. Log calls and sms in my app, block unwanted numbers, etc. I know the IPhone SDK doesn't provide that but I have been googling this and what I got was an app called iBlackList. Although it runs on jail-broken phones but it does my required functionality. I wonder how? Has anyone idea about how these tasks can be accomplished?

    Read the article

  • Why is there no * in front of delegate declaration ?

    - by gotye
    Hey guys, I just noticed there is no * in front of the declaration for a delegate ... I did something like this : @protocol NavBarHiddenDelegate; @interface AsyncImageView : UIView { NSURLConnection* connection; NSMutableData* data; UIActivityIndicatorView *indicator; id <NavBarHiddenDelegate> delegate; } @property (nonatomic, assign) id <NavBarHiddenDelegate> delegate; - (id)initWithUrl:(NSString*)url; @end @protocol NavBarHiddenDelegate - (void)hideNavBar; @end It works perfectly well but as I am used to always but a * in front of objects I declare, why not for this one ?!? Thank you, Gotye.

    Read the article

  • How to modify web page elements loaded in a browser

    - by Trilok
    I want to associate some actions with keys (of a keyboard) and then modify the contents of a webpage loaded in the browser. For example, I'll write a firefox plugin and that would be listening to some keyboard events. Based on a key press (or something like that) I want to modify the html code of the page. For example, I would like to change the color of a link. Any suggestions on how can I go about doing this?

    Read the article

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