C#, Windows 10 x64, Services, SystemEvent Handling
On this page https://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents(v=vs.110).aspx
you see "Example 2" which shows a simple service for Windows which includes a hidden form for the message loop. There is a event handler for "UserPreferencesChanged" and "TimeChanged". (I also want to add "DisplaySettingsChanged" <--- which is the main reason I am looking into this)
I cannot get this service receiving events properly. For example, I get sporadic notifcations in the event log that Time has changed, but I do NOT get anything when change "user preferences" (like where they say changing mouse settings) and also absolutely nothing when I add "DisplaySettingsChanged" or "DisplaySettingsChanging"
(see: https://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.displaysettingschanged(v=vs.110).aspx)
Absolutely nothing. I have the service running and watch the event log (as the example tells me), I am changing screen resolutions etc. or mouse settings, nothing. I am stumped. Has ANYONE gottin this to work?
(Using C# in VS2015, one version I made with the "Windows Service" template and one other where I basically copy/pasted the example 1:1, both don't work)
Thanks!
Related
I have a very strange situation here with CEF Sharp x86 (67 with latest cef.redist 3.3497.1841), but originally reported with v49. It's very crazy, so I'm just looking, maybe somebody have stumbled upon anything similar. We host WPF ChromiumWebBrowser inside WinForms UserControl (via ElementHost) and it's running inside 3rd party application, with which it does not interact in any way (so it's a plugin to this host application). For about 100 or so users everything is ok, but for a single person this happens: webpage loads and displays correctly, but the ChromiumWebBrowser.IsBrowserInitialized flag is always false.
Now, by 'user' I don't mean Windows account, just a user in totally unrelated 3rd party application, logging-in against 3rd party userid/password verification - unrelated to any windows settings. So as crazy as it sounds we've tried it on multiple computers on multiple windows accounts, using different user ids for the application, and the result is still the same - for this one userid there is a problem, for others - all ok.
I wonder if anyone has had such crazy experience with CEF. I'm betting on some bug in .NET layer, as the actual browser works fine - webpage is rendered, you can browse normally. Also this has sth to do with CEF run as plugin to this exact 3rd party app - if I run a test winform app with same setup - user control -> element host -> WPF ChromiumWebBrowser, all is ok. CEF log is not much help, no errors other than in OK situation.
I'm not attaching any code or logs, I don't think it'd be helpful in this case. Just for more background the plugin has been around for almost 3 years with not a single bug reported, except this case. Just to make it clear - I need this flag to be true to be able to inject JS calls into the plugin.
Ok, so it turned out to be a case of opening 2 instances of browser within single process. One browser window was initializing and working fine, second was was displaying page, but reporting 'not initialized'. It became clear only when I went to customer and actually saw the scenario, because they did not report that they opened 2nd instance. I this case, they don't need 2nd instance, so that was the fix, maybe there is an error I our code, I'll follow up this issue once we do more through analysis.
I am making a custom OPC Client application in WPF to communicate with a Kepware server. One of the functions is to configure a tag, including setting it's host and server. Now I could do this manually with calls to the Kepware ClientAce API for searching for valid network hosts and valid servers on that host, but ClientAce includes a .dll that already provides a tree control the user can browse directly. However, this out of the box control is in Windows Forms.
So I have this WPF Window that I launch as Modal Dialog with ShowDialog(). Within this window is a WindowsFormsHost element that contains the aforementioned server browsing control. It's works pretty well for the most part, including providing an event to handle when the user has made a new selection in the tree control. That event has a boolean parameter that indicates if the new selection is a server. A good thing since that's the very thing I'm trying to keep track of here.
It also provides a "server has been double-clicked" event, which I handle and have decided to interpret as a shortcut to the user selecting that server as the one they want. (Otherwise, they have to click a separate button for the currently selected server which I stored based on the aforementioned selection event.)
All good so far....
...But! There is another functionality Kepware added (well actually there's a few, but I'm not worried about those at this point). The user has the ability from a context menu to delete a server from the tree. For some reason, this is throwing a null exception (though, it successfully deletes the server from the tree). This is a very bad thing for my purposes because...:
I don't have any idea what leads to this. There is no stack trace. There is no extra information. Just that something, somewhere in that control has thrown an unhandled exception that I must now deal with.
I can't remove the context menu item. There's another context menu item that I can set a property in the XAML to remove, but that one isn't throwing the exception. It's the one I can't remove that is.
There's a lovely event called "ContextMenuItemClicked". It'd be nice if I could handle that. I just go into my handler, put a try/catch around the logic, and ignore the null exception that has absolutely nothing to do with me and what I'm trying to accomplish. However, the universe is against me here, and has decided that this is a mouse-click event, which Windows Forms doesn't want to propogate. I've searched around and this seems to be a common issue with Windows Forms and WPF interop. Mouse-clicks just don't play nice with the interop services. I tried. I really did. But the handler I made just sits there unused. Odd thing is, while I can understand why I can handle the "SelectionChanged" event from this control, I'm curious as to what Kepware did to make the "ServerDoubleClick" event propogate up, and why they didn't decide to extend that same courtesy to the context menu click.
So there I am. With an exception that isn't my fault, that I don't care about, and I apparently can't prevent. I just want to throw it away and move on. However, it's in a modal dialog, and I need to have this exception handled before the method that called ShowDialog() and popped this window up in the first place. (I'll spare you the details as to why. This post is long-winded enough as it is.)
Is there a way I can either somehow propogate the mouse events up, or trap this exception somewhere in my window class so that it doesn't propagate up the stack into the calling method?
We have a C# .NET 3.5 UI client application that runs in a multiple monitor desktop environment (typically 4 screens) on Windows 7. Every so often, after running several of these applications, the screen stops redrawing.
Controls continue to be reactive to clicks or keypress and values can be updated programmatically, but the entire form is not redrawn to reflect any changes. For example buttons that are enabled/disabled based on state may be remain grayed out, but be reactive to clicks or vice versa. Buttons do not animate when clicked.
Workaround: minimizing and restoring the window appears to clear the problem. After this, the application begins to draw correctly.
The must frustrating aspect of this problem is that programmatically, everything appears to be running normally. No exceptions are caught in our logs. Nothing was visible in the system event logs. We have not found a way to detect this condition is happening yet.
Other miscellaneous aspects: logging uses log4net, server communication layer uses ZMQ
Update:
Calling form Invalidate() and Update() does not fix the problem.
When dragging the window between screens, it shows different values on each screen.
Minimize/restore still resolves the issue.
I can't be sure of anything without seeing the app and the code, but my best guess is someone calls .SuspendLayout() before a complicated update, and an exception (probably swallowed) prevents the code from ever reaching the corresponding .ResumeLayout(). To test this, try adding a button that calls .ResumeLayout() for the form.
It seems the solution is there:
1) http://blogs.msdn.com/b/alejacma/archive/2009/08/11/controls-won-t-get-resized-once-the-nesting-hierarchy-of-windows-exceeds-a-certain-depth-x64.aspx
2) http://support.microsoft.com/kb/2664641/en-us
I have to stop applications when the window is closed. The window stays in the memory when click the (x) button. How can i remove the app in memory? Also another question is that i want the application to be installed when hard restart the pocket pc, how can i do it?
Thanks
By default the form will just hide when you click the X in the top right. You need to set the "MinimizeBox" property of the form to "False" for the application to close instead.
Installing the application on hard restart (often referred to as cold boot) requires that you put a CAB file for the application on the flash (persistent) memory of the device. You will then normally have to write a script and place that somewhere to call the CAB. This can vary from device to device so you'll have to look that one up.
Setting the form's MinimizeBox property to False causes the OK button to appear.
The Ok button is for closing the application instead of minimalizing
To prevent to application from minimizing which is the default behavior for PocketPC applications, set the MinimizeBox option to false on the form.
As for your second option that might be trickier because it depends on the PDA. If it has persistent memory you could put it there, and find a way to run the CAB file during initialization.
[Update]
It would appear that there is a Startup Folder in the windows menu. Perhaps you could write a utility that checks if your application is installed and if not launches the CAB installer.
The default behavior is indeed minimizing the application. Using a custom task manager which replaces the [x] you can tune this behavior. Some vendors (for instance HTC) include a custom taskmanager exactly for this purpose.
A generic but good task manager is WkTASK, here is the relevant feature description:
X button
Using the X button, you can
use some actions as follows:
Tap: really close
Tap&Hold: show context menu
Drag: some gestures (To show a program launcher, drag toward down. To
show Today, drag toward left.)
WkTASK offers a lot more, but you can fine tune it to do only what you want.
I posted this answer (more of an idea really) but haven't been able to find out for sure which message triggers a WinForms Form.Load event. From Spy++ and some reading I suggested it might be WM_SHOWWINDOW, but I'd like to be sure.
Also, other than Spy++ is there a better way to see exactly which windows message triggered a .Net event? Even after switching off some event types in Spy++ the log window fills up very quickly.
Thanks.
There isn't a specific windows message which corresponds to the Load event on the Form class. The event is simply fired the before first time the window is made visible after the creation of the window handle of the Form.
It's used for initialization which requires the window handle of the Form to be created but before the Form is shown for the first time.
I'm guessing here, but it might be instructive to configure your dev environment to use Microsoft's source server, then have a look through the System.Windows.Forms code. See Shawn Burke's blog entry Configuring Visual Studio to Debug .NET Framework Source Code.