开发者

VMware event hooks in .NET

I'm developing an in-house .NET application that will be run on a VM (with VMware), and want to know if there's a way to get notifications from VM system events (like suspending, resumed, etc.)

Anyone know of a convenient way to do that? The virtual machine has VMware Tools installed, does that provide a .NET API for hooking events?

EDIT: In particular, I'm interested in when the system has just resumed. I assumed that this doesn't correspond to any "regular" Windows system event (after all, the whole point of suspending and resuming a VM is that Windows has no idea what happened). Am I mistaken? Will that trigger an event?

EDIT 2: I wrote this quick console app to hook all the System Events I could think of, and get nothing when I suspend/resume:

static void Main(string[] args) {

    SystemEvents.DisplaySettingsChanged += (sender, e) => Console.WriteLine("Display settings changed");
    SystemEvents.EventsThreadShutdown += (sender, e) => Console.WriteLine("Events thread shutdown");
    SystemEvents.PowerModeChanged += (sender, e) => Console.WriteLine("Power mode changed");
    SystemEvents.SessionEnding += (sender, e) => Console.WriteLine("Session ending");
    SystemEvents.SessionSwitch += (sender, e) => Console.WriteLine("Session switch");
    Sys开发者_运维问答temEvents.UserPreferenceChanging += (sender, e) => Console.WriteLine("User preference changing");

    Console.ReadLine();
}


are there any vmware-specific events you'd be listening for? Otherwise it sounds like you'd be better off listening for those events from Windows


Take a look at WM_POWERBROADCAST -- http://www.pinvoke.net/default.aspx/user32.RegisterPowerSettingNotification


OK, so I've given up on looking for an easy .NET hook for this, but if someone else stumbles on this and wants to know how I solved it:

I have a timer in my app that fires regularly (every 10 seconds), and compares the current time to the last time. If the time is appreciably longer than 10 seconds, I assume that the computer has either been asleep or suspended, and refresh my app as needed.

A little hacky, but the timer adds nothing to the program's CPU or memory usage, so I figure it's not horrible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜