private MessageProcessingHealthCheck <string> CreateHealthCheck(bool exceededMaxTimeSinceLastProcessedMessage, int itemCount) { var maxTimeSinceLastProcessedMessage = TimeSpan.FromMilliseconds(100); var config = new MessageProcessingOptions { MaxTimeSinceLastProcessedMessage = maxTimeSinceLastProcessedMessage }; var queue = new Mock <IBackgroundTaskQueue <MotorCloudEvent <string> > >(); queue.Setup(q => q.LastDequeuedAt).Returns(exceededMaxTimeSinceLastProcessedMessage ? DateTimeOffset.UtcNow.Subtract(maxTimeSinceLastProcessedMessage + TimeSpan.FromMilliseconds(50)) : DateTimeOffset.UtcNow.Subtract(maxTimeSinceLastProcessedMessage - TimeSpan.FromMilliseconds(50))); queue.Setup(q => q.ItemCount).Returns(itemCount); return(new MessageProcessingHealthCheck <string>( Options.Create(config), queue.Object)); }
/// <summary> /// Starts processing the raw input messages received by the application. /// </summary> /// <param name="windowHandle">Handle to the target window that will receive the messages.</param> /// <param name="options">The options for the processing and filtering of messages.</param> /// <remarks> /// Call this function to start filtering and processing raw input messages through the message pump of a target window. /// <para/> /// Using this function, the raw input data is processed one message at a time. In contrast, you can use buffered processing /// by calling <see cref="ProcessMessages"/> to process the queued raw input messages in bulk. /// <para/> /// This function installs a <see cref="IMessageFilter"/> that intercepts and processes the raw input messages received by /// the application. See <see cref="MessageProcessingOptions"/> enumeration for more information. /// </remarks> public static void StartProcessingMessages(IntPtr windowHandle = default, MessageProcessingOptions options = MessageProcessingOptions.Default) { if (rawInputMessageFilter != null) { return; } targetWindowHandle = windowHandle; rawInputMessageFilter = new RawInputMessageFilter(); if (options == MessageProcessingOptions.Default) { Application.AddMessageFilter(rawInputMessageFilter); } else { MessageFilterHook.AddMessageFilter(windowHandle, rawInputMessageFilter); } }