LooneyCode Posted February 19, 2004 Posted February 19, 2004 Recently an old program of mine developed a strange problem. It used to work fine, then one day it started misbehaving, even though I had not changed anything for months. What's happening is this: I have a method that has to get called when the application goes idle. (The method graphs data it is acquiring from an external source.) Anyway, in some situations the idle event which is supposed to call the method, somehow isn't firing. This only happens if I click on certain kinds of controls, such as check boxes, buttons, or radio buttons. If I leave the cursor in a text box, the method called by the event tied to Application.Idle will continue to fire as it should. After I click on a radio button, and the idle stops firing, if I simply flick the mouse cursor, it will fire again.... but only once, not continuously. I have to move the mouse again, or go click into a textbox to get the thing to keep firing during idle time. If I "fudge fix" and make the click events for button controls refocus into a textbox after their normal code is finished, then the idle event works fine (but I don't really want to be forced to use this fudge fix.) Anyway, none of this used to happen, and every time the app went idle it would continuously call my method, regardless of what kind of control I had clicked on last. Then one day, this strange behavior started. I've put little flags and triggers into the method that gets called, just to see if it's even getting called, and it isn't. Anyone had this problem before, or have any ideas what could be happening? Thanks. Since the code hasn't changed, all I can figure is Windows Update changed something, or some other background process is co-opting the idle on my application. Here's how the method gets attached to Application.Idle. Pretty basic really: [sTAThread] static void Main() { PindiForm1 myForm = new PindiForm1(); Application.Idle += new EventHandler(myForm.refreshTrace); Application.Run(myForm); } /* Here's the method that doesn't ever get called if I clicked on * a button or checkbox.... unless I flick the mouse cursor or * click in a textbox, or force the click event to refocus in a textbox * when I'm done : */ private void refreshTrace(object sender, System.EventArgs e) { MessageBox.Show("Hi, I've been called!"); //debug tester DateTime right_now = DateTime.Now; if (right_now > whenSignalDraw.AddMilliseconds(2200) ) { RedrawSignalTrace(); // regraphs data whenSignalDraw = DateTime.Now; } } Quote
*Gurus* divil Posted February 20, 2004 *Gurus* Posted February 20, 2004 Are you sure this is the event you're looking for? It's designed to fire once all windows messages have been processed and there are no more left in the queue. Then it won't fire again until after some more windows messages have been processed. Are you sure a timer wouldn't be more appropriate? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.