Adhara wrote: ↑Wed 12. Apr 2023, 11:13
Thanks for the free C# lesson.
You're welcome.
Adhara wrote: ↑Wed 12. Apr 2023, 11:13
Finalizers are not very common in .NET, Worker should probably implement IDisposable, if it needs to release managed resources.
Actually, they are. You just do not see them. The finalizer is first implemented by the class object, and all other classes derived from it. I think you misunderstand something: IDisposable is mainly used for releasing "
unmanaged" resources (not managed). The Worker class uses no unmanaged resources (like pointers to files or such things). The event mechanism is done in a managed way.

- from learn.microsoft.com
- IDsposable.PNG (11.98 KiB) Viewed 1674 times

- from learn.microsoft.com
- Finalizer.PNG (31.49 KiB) Viewed 1674 times
Adhara wrote: ↑Wed 12. Apr 2023, 11:13
this would also allow using statement and make Worker lifecyle more obvious.
Yes, implementing IDispose would allows writing an "using" statement with the Worker objct. Though, the the Worker class was not designed with this purpose. It is rather designed to be used for a large period of time (normally as long as the applcation itself), to help users writing apps like the PCAN-View. It makes no sense to have a class like the Worker in a using statement, just for send or receive a couple of messages. For this purpose, you can easily use the class Peak.Can.Basic.Api, and either write your own worker or directly call the API functions.
Adhara wrote: ↑Wed 12. Apr 2023, 11:13
To avoid event registration/deregistration issues it would be nice to register a callback not an event handler, the callback could then be called passing directly the queue.
A callback is more suitable for having single indications (like when a time consuming process ends). It is also a design question. Is like asking to have a Callback instead of the Elapsed-Event within the class System.Timers.Timer. Note also that the MessageAvailable event tells you the index of the queue you need to poll.
Adhara wrote: ↑Wed 12. Apr 2023, 11:13
This is important because at the time being when the event handler is called there is a threading issue on the worker object itself, since I am requested to call the dequeue method on it.
Not sure to understand. This is not an issue, but a normal process. Reading is done in another thread. This is also mentioned in the help:

- from docs.peak-system.com
- Synch.PNG (32.24 KiB) Viewed 1674 times
Adhara wrote: ↑Wed 12. Apr 2023, 11:13
I would at least make it obvious from the doc that the sender is actually the worker itself, so using it inside the event handler should be safer.
"it is obvious" --> Sorry, but as I wrote before, this is the normal way this is programmed using C#.
We appreciate the opinions and suggestions from our customers. Even when we think that the Worker class already saves you a lot of work, it is easy to use and to understand, we will check if we can enhance it to be even more comfortable. Do not hesitate to post any idea or improvement suggestion you may have (you can also use the forum
Suggestion and Feature Requests). We cannot promise to implement these, but we will check if we can.
As the actual questions are answered I am closing this post. Feel free to open a new one if you have further questions.