//******************************************************************************************** // Function: RegisterForDestinationCostChangeNotifications // // Description: Registers for Destination cost change notifications, and waits in the message loop. // //******************************************************************************************** static void RegisterForDestinationCostChangeNotifications() { var hr = GetDestinationAddress(out var sockAddr); if (hr == HRESULT.S_OK) { //Registration is allowed only once, before unregister. if (g_pSinkDestCostMgr is null) { try { g_pSinkDestCostMgr = CNetCostEventSink.StartListeningForEvents(typeof(INetworkCostManagerEvents).GUID, sockAddr); Console.Write("Listening for Destination address based cost change events...\n"); } catch (Exception ex) { Console.Write("Registration failed, please try again. \n"); hr = ex.HResult; } } else { Console.Write("You have already registered for Destination cost notifications. Please unregister before registering for events again.\n"); Console.Write("The Win32 Cost API feature allows multiple registrations, but the sample SDK does not allow this. \n"); } } DisplayError(hr); }
//******************************************************************************************** // Function: UnRegisterForConnectionCostChangeNotifications // // Description: // //******************************************************************************************** static void UnRegisterForConnectionCostChangeNotifications() { if (g_pSinkConnectionCostMgr != null) { g_pSinkConnectionCostMgr.Dispose(); Console.Write("Successfully cancelled Registration for Connection Cost Notifications\n"); g_pSinkConnectionCostMgr = default; } else { Console.Write("You have not registered for Connection cost Notifications\n"); } }
//******************************************************************************************** // Function: RegisterForMachineCostChangeNotifications // // Description: Registers for machine cost change notifications, and waits in the message loop. // //******************************************************************************************** static void RegisterForMachineCostChangeNotifications() { //Registration is allowed only once, before unregister. if (g_pSinkCostMgr is null) { try { g_pSinkCostMgr = CNetCostEventSink.StartListeningForEvents(typeof(INetworkCostManagerEvents).GUID); Console.Write("Listening for Machine cost change events...\n"); } catch (Exception ex) { Console.Write("Registration failed, please try again. \n"); DisplayError(ex.HResult); } } else { Console.Write("You have already registered for Machine cost notifications. Please unregister before registering for events again.\n"); Console.Write("The Win32 Cost API feature allows multiple registrations, but the sample SDK does not allow this. \n"); } }