Re: How to find if Application has Focus



On Wed, 14 May 2008 07:42:27 -0700, Albe V° <vaccariTOGLI@xxxxxxxxxxx> wrote:

One of the form of the solution has a timer, and the timer calls a refresh procedure.
Unfortunately, there is a .Net documented bug that makes the app crash if graphical refreshes are frequently called when the app itself is in background ina terminal server session.
Now, a customer is in this unlucky situation: the operators use then client in each own terminal server session, the client makes a graphical layout refresh according to some SqlServer data, but if the operator opens another application, and puts my client application in background or minimized, the app itself crashes.
At the present, MS does not provide any solution, so the only thing I can do is to try to avoid this refresh.

But: How can I determine if the app is in background?

That's an unfortunate bug.

My first thought is to wonder whether "refreshes are frequently called" is so frequent that it wouldn't matter to the user to simply slow them down all the time. At what frequency does a graphical update result in a crash? Would it be feasible to simply reduce your visual refresh frequency to some rate below this critical rate?

Barring that, I don't believe what you want is possible using only the ..NET Framework. I haven't noticed anything like this available directly in the framework. However, Windows certainly provides that information and you can get at it through various means. I'd guess the most direct way would be to use the Application.AddMessageFilter() to watch for WM_ACTIVATEAPP messages. Your application will receive one with it changes state from foreground to background or vice a versa.

If that doesn't do it, you might submit a support request to Microsoft via their web site. They provide two free support requests per product, and my experience has been that a) they extend this to development questions, and b) if the support request is a consequence of some bug in their products, they credit back the request to your product ID. I've had about a 50% success rate getting actual solutions for bugs in Windows this way, and have always at least received a courteous effort to try to solve the problem.

Granted, my sample size is low (maybe a half-dozen at most over the last ten years or so), but it's worth a try if the above doesn't help. The bug you're dealing with is fairly serious and seems clearly specific to a particular Microsoft product; I would expect them to be reasonably proactive in trying to help you deal with it.

Pete
.



Relevant Pages

  • Re: Generating Unique Numbers on a Form with Multi-users
    ... but I always do a refresh immediately and don't ... Private Sub cmdNext_Click ... I haven't worked on this app in a while but IIRC "Me.AllowAdditions = False" ... instant is a remote possibility, so remote that the risk is negligible. ...
    (microsoft.public.access.forms)
  • Re: [opensuse] Changing email address in Novell Bugzilla?
    ... pasword instead, enter, and I'm back at the correct bug report. ... I guess you don't use your browser history much. ... When you refresh and it ... For me, that's most bugs, and twice as ...
    (SuSE)
  • Re: [opensuse] Changing email address in Novell Bugzilla?
    ... pasword instead, enter, and I'm back at the correct bug report. ... much time to find the right bug in history due to twice as much scrolling to ... that doesn't match your current login state. ... When I refresh, clicking on the refresh icon, the history doesn't change. ...
    (SuSE)
  • Re: Maximised windows leave space at top of screen
    ... I think the panel for this app is a toolbar along ... > I'm having a problem where maximised screens from *all* applications ... > refresh function - right clicking the desktop and selecting refresh ... > does not refresh this space leaving strip remnants of the window. ...
    (microsoft.public.windowsxp.general)
  • Menus make things go faster! Why?
    ... I'm writing an app that rotates a 3D image on a PocketPC. ... Release mode helps only slightly - making things refresh at around 400 msec ... emulator, my animation immediately kicks into fulls speed (moving really, ... run at proper speeds? ...
    (microsoft.public.windowsce.embedded.vc)