使用 GUI 包装器编写 .NET 控制台应用程序
我正在编写一个 .NET 控制台应用程序来上传文件。但是,我将来可能必须为此应用程序创建一个 GUI 前端。考虑到这一点,我怎样才能最好地设计我的控制台应用程序?传递参数很简单,但如何在 GUI 中显示进度和错误?
I am writing a .NET console application to upload files. However, I might have to create a GUI front end for this application in the future. How can I best design my console application with this in mind? Passing arguments will be simple, but how can I show progress and errors in the GUI?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议不要尝试让控制台应用程序成为前端的集成点,而是创建一个公共共享库来托管所有业务逻辑,并在该级别集成您的 UI。
I would suggest that instead of trying to make your console application be the point of integration for a front-end, instead create a common shared library to host all the business logic, and instead integrate your UI at that level.
保持应用程序的表示和逻辑分离。您可以围绕界面设计您的应用程序。例如,如果您创建并使用
IProgress
接口来报告进度,您的控制台应用程序可以使用 Console.Write 来报告进度,但您的 GUI 应用程序稍后只能使用相同的接口来更新进度条。Keep your application presentation and logic decoupled. You can design your application around interfaces. For example, if you create and use an
IProgress
interface for reporting progress, your console application can use Console.Write to report progress, but your GUI application, later, can just use the same interface to update a progress bar.不要让 GUI 与控制台应用程序交互。将逻辑与界面分离,使每个界面与公共逻辑库交互
Don't make the GUI interact with the console app. Separate the logic from interface and make each interface interact with the common logic library(ies)