从类库方法中获取进度状态

发布于 2024-08-29 20:55:32 字数 388 浏览 2 评论 0原文

我正在做的这个应用程序使用类库(如果我敢这样称呼它)来完成大部分工作: 其中的 2 个主要方法(DoWork 和 UndoWork)使用其他类来实现他们的目标。 现在可以了,我想退出控制台测试环境并创建一个 GUI。

我如何获取 DoWork() 方法的状态来更新进度条? 我应该对类库(当前与控制台和 Windows.Forms 一起使用)进行多重更新吗?问题是我肯定必须让类库使用 Window.Forms,这会弄乱控制台测试应用程序(而且有很多这样的应用程序 - 我一直测试,然后一起测试)。

您能否建议一些想法,或者我可以阅读有关想法的地方(毕竟,编写此程序的全部目的是学习)?

哦,顺便说一句,像“远见”或“计划”这样的建议可能在这里没有帮助......(现在,无论如何!) - 但在未来的项目中肯定会!

This app that I am doing uses a class library (if I dare call it that) to do the bulk of the work:
2 main methods in there (DoWork and UndoWork) use the other classes to achieve thier goal.
Now that that works, I want to get out of the Console test enviroment and do a GUI.

How would I get the status of say, the DoWork() method to update a progress bar?
Should I multilate the class library (which currently works with the Console and Windows.Forms) to update? The problem with that is that I would surely have to make the class library use Window.Forms which will mess up the console testing apps (And there are lots of them - I tested all the way through, and then all together).

Could you suggest some ideas, or places I can read up about ideas (the whole point of writing this this program is to learn, afer all)?

Oh, by the way, suggestions like "foresight" or "planning" probably won't help here...(now, anywyay!) - But certainly will in future projects!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉城 2024-09-05 20:55:32

无需修改 DoWork() 来实际绘制状态更新,只需对其进行修改以向您在初始化 DoWork 时(可选)提供的委托提供进度更新()。

这样,当您是控制台应用程序时,您可以提供一个仅打印状态更新的委托,并且可以提供一个导致进度条在 GUI 应用程序中更新的委托。

Instead of hacking up DoWork() to actually draw the status update, simply modify it to provide progress updates to a delegate that you (optionally) provide while initializing DoWork().

This way, you can provide a delegate that simply prints the status update when you're a console app, and you can provide one that causes the progress bar to be updated in the GUI app.

破晓 2024-09-05 20:55:32

您应该让该方法采用一个附加参数来实现接口或委托来接收进度报告。
然后,您应该对控制台应用程序的界面进行无操作实现,并为 WinForms 更新 ProgressBar 控件。

You should make the method take an additional parameter that implements an interface or delegate to receive progress reports.
You should then make a no-op implementation of the interface for console apps, and an implementation that updates a ProgressBar control for WinForms.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文