@@ -38,11 +38,18 @@ public async Task TestLastPressedKey()
3838If this class is used as an ` IEventSimulator ` in the tested code, then the ` SimulatedEvents ` property can be checked to
3939see which events were simulated using the test instance.
4040
41- It's recommended to stop the global hook and wait for it to stop before asserting any events. The test global hook runs
42- an event loop using ` BlockingCollection ` , and posting an event will add this event to this collection for the global
43- hook to dispatch. Since these actions are done in different threads, it is not guaranteed that an event will be
44- dispatched immediately after it is simulated. ` Run ` and the task returned by ` RunAsync ` will complete after every event
45- has been dispatched.
41+ ` TestGlobalHook ` can be used with two different threading modes - the simple mode and the event loop mode.
42+
43+ When running in simple mode (the default mode) the hook will dispatch events immediately in the same thread which
44+ simulates them.
45+
46+ When running the event loop, the hook will run an actual even loop on the thread on which ` Run ` was called. When
47+ simulating events, they will be posted to the event loop, and then dispatched in the hook thread. This mode is much more
48+ difficult to use correctly, so it is useful only when it is important for event handlers to run in the same thread on
49+ which the hook itself is running. It's recommended to stop the global hook and wait for it to stop before asserting any
50+ events. Since these actions are done in different threads, it is not guaranteed that an event will be dispatched
51+ immediately after it is simulated. ` Run ` and the task returned by ` RunAsync ` will complete after every event has been
52+ dispatched.
4653
4754Other than that, members of ` TestGlobalHook ` are quite straightforward; the API reference should be viewed for more
4855info.
@@ -56,12 +63,19 @@ If the low-level functionality of SharpHook should be mocked, or mocking should
5663then ` SharpHook.Testing.TestProvider ` can be used. It implements every interface in the ` SharpHook.Providers ` namespace,
5764and as such, it can be used instead of normal low-level functionality providers.
5865
59- Like ` TestGlobalHook ` , this class can post events using the ` PostEvent ` method and dispatch them if ` Run ` has been
66+ Like ` TestProvider ` , this class can post events using the ` PostEvent ` method and dispatch them if ` Run ` has been
6067called. It also contains the ` PostedEvents ` property.
6168
62- It's recommended to stop the provider and wait for it to stop before asserting any events. The test provider runs an
63- event loop using ` BlockingCollection ` , and posting an event will add this event to this collection for the provider to
64- dispatch. Since these actions are done in different threads, it is not guaranteed that an event will be dispatched
69+ ` TestProvider ` can be used with two different threading modes - the simple mode and the event loop mode.
70+
71+ When running in simple mode (the default mode) the provider will dispatch events immediately in the same thread which
72+ simulates them.
73+
74+ When running the event loop, the provider will run an actual even loop on the thread on which ` Run ` was called. When
75+ simulating events, they will be posted to the event loop, and then dispatched in the hook thread. This mode is much more
76+ difficult to use correctly, so it is useful only when it is important for event handlers to run in the same thread on
77+ which the hook itself is running. It's recommended to stop the provider and wait for it to stop before asserting any
78+ events. Since these actions are done in different threads, it is not guaranteed that an event will be dispatched
6579immediately after it is simulated. ` Run ` and the task returned by ` RunAsync ` will complete after every event has been
6680dispatched.
6781
@@ -82,6 +96,3 @@ var simulator = new EventSimulator(simulationProvider: testProvider);
8296> ` TaskPoolGlobalHook ` shouldn't be used this way since its event handlers are asynchronous and there is no built-in
8397> way to know when they are actually executed. As such, it's difficult to check event handler results. If you want
8498> to use a real hook, e.g. for integration testing, then use ` SimpleGlobalHook ` instead.
85-
86- It's recommended to stop the provider and wait for it to stop before asserting any events. The test provider runs
87- an event loop just like the test global hook so the same constraints apply to its usage.
0 commit comments