I have small in C# project which has several classes.
The First copies the files, the second synchronizes database SQL CE from SQL SERVER, and the third is packed to ZIP files etc.
I want to almost every function in these classes repoted to what she did, or failed to do something or not.
At this moment i am so in place when something happened to report it calls public event EventHandler OperationStatusChanged, in the StatusEventArgs i pass on the string with a description.
Handling event is in a class that is executing an instance of the class.
Ultimately, I want that all messages, error, etc are stored in the database using Nlog.
It is possible to do it more elegantly than calling event and its handling
Thank you for your time.
开发者_Python百科Tom
There is nothing wrong in event handling and it is appropriate for asynchronous operations.
However, it looks like your different operations are sequential so your calling class could call them one after the other. To avoid blocking your user interface, start the calling class loop in a separated thread and inform the UX at the end of each operation.
精彩评论