开发者

C# Class Design - Events & long running methods

I have a class that has some long running methods, in which they do DB queries, retrieve a list of objects, iterate through them and do some IO work.

How should this class design be approached?

Should I have OnComplete events in my class if the task completes?

I do want to开发者_开发百科 give the consumer the ability to cancel/abort, so simply reporting when the method completes is not good enough.

Initially I had a BackgroundWorker (and much of the logic) in my UI code, however I separated the logic so it's all in a separate library.

I was considering adding the background worker in the class, and simply passing creating similar events as is raised by the background worker. Is this the best approach?


There is nothing inherintly wrong with using a background worker in your class. Probably what you are really looking for is the Event-based Asynchronous Pattern.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜