Skip to content

Commit ba609a3

Browse files
Update the docs for version 6.1.0
1 parent f2734ca commit ba609a3

4 files changed

Lines changed: 34 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# SharpHook Changelog
22

3+
## [v6.1.0](https://github.com/TolikPylypchuk/SharpHook/releases/tag/v6.1.0) (May 23, 2025)
4+
5+
- The ability to control the behaviour of `TestGlobalHook` and `TestProvider` (simple dispatching from version 5 vs an
6+
event loop from version 6) was added. The simple behaviour from version 5 is the default as it is much easier to use.
7+
38
## [v6.0.0](https://github.com/TolikPylypchuk/SharpHook/releases/tag/v6.0.0) (May 18, 2025)
49

510
### Platform Support

docs/articles/about.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ You need .NET 9 to build SharpHook.
5555

5656
## Changelog
5757

58+
### [v6.1.0](https://github.com/TolikPylypchuk/SharpHook/releases/tag/v6.1.0) (May 23, 2025)
59+
60+
- The ability to control the behaviour of `TestGlobalHook` and `TestProvider` (simple dispatching from version 5 vs an
61+
event loop from version 6) was added. The simple behaviour from version 5 is the default as it is much easier to use.
62+
5863
### [v6.0.0](https://github.com/TolikPylypchuk/SharpHook/releases/tag/v6.0.0) (May 18, 2025)
5964

6065
#### Platform Support

docs/articles/migration.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ All obsolete values in the `KeyCode` enum were removed.
3030

3131
`HookException` doesn't support `BinaryFormatter` serialization anymore.
3232

33-
The behaviour of `TestGlobalHook` and `TestProvider` was changed. Instead of dispatching events in the same thread that
34-
simulates them, they now instead add events into an event loop running on a different thread. `TestProvider` now throws
35-
an exception if `Run` or `RunAsync` is called and it's already running.
33+
`TestProvider` now throws an exception if `Run` or `RunAsync` is called and it's already running.
3634

3735
The minimum .NET Framework version was bumped to 4.7.2 and direct support for .NET 6 and .NET 7 was dropped (though they
3836
are still supported through .NET Standard 2.0).

docs/articles/testing.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,18 @@ public async Task TestLastPressedKey()
3838
If this class is used as an `IEventSimulator` in the tested code, then the `SimulatedEvents` property can be checked to
3939
see 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

4754
Other than that, members of `TestGlobalHook` are quite straightforward; the API reference should be viewed for more
4855
info.
@@ -56,12 +63,19 @@ If the low-level functionality of SharpHook should be mocked, or mocking should
5663
then `SharpHook.Testing.TestProvider` can be used. It implements every interface in the `SharpHook.Providers` namespace,
5764
and 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
6067
called. 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
6579
immediately after it is simulated. `Run` and the task returned by `RunAsync` will complete after every event has been
6680
dispatched.
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

Comments
 (0)