设计多层应用程序以使用进度条

发布于 2024-10-07 14:25:30 字数 176 浏览 8 评论 0原文

我有一个 C# 多层应用程序,应该在数据库上执行任务(如果第一次使用,我们可以创建数据库并用一些数据填充它)。当我最初设计该应用程序时,我没有考虑可能的进度条控件,更不用说任何类型的进度报告了。如何修改应用程序的设计,以便能够向 UI 层报告数据库操作进度?是否有一种可重复使用的解决方案,并且不会强迫我修改所有功能以获取额外的报告输入?

I have a multi tier application in c# that is supposed to perform tasks on a database (If first time use, we may create the database and fill it with some data). When I initially designed the application I didn't account for a possible progress bar control, let alone any reporting of progress of any sort. How can I modify the design of the application to be able to report database operations progress to the UI layer? Is there a solution out there that is reusable and doesn't force me to modify all my functions to take additional inputs for the reporting?

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

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

发布评论

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

评论(3

暗藏城府 2024-10-14 14:25:30

正如格雷格所说,前面还有很多工作要做。然而,解决这个问题的方法有很多,最适合您的方法取决于哪些上下文信息已经从客户端传递到应用程序/数据库层。例如,如果在执行查询/事务的正常过程中将会话令牌或事务标识符从客户端传递到应用程序,或者将确认引用从应用程序异步传回客户端,则对于那些查询/事务,进度报告是必要的,您可以让应用程序更新客户端可以查询的状态表。这可以减少所需的返工量。基本上,您需要考虑已经到位的“中间件”,并查看是否可以利用其中任何一个来关联跨层的事务。

As Greg said, there's a lot of work ahead. However, there are many ways in which to approach the problem, and the best for you depends on what contextual information passes down from the client to the application/database layers already. For example, if a session token or transaction identifier is passed from the client to the application in the normal course of executing a query/transaction or an acknowledgement reference passed back asynchronously from the application to the client, then for those queries/transactions for which progress reporting was necessary you could have the application update a status table that the client could query. This could reduce the amount of re-work required. Basically, you need to consider the "middleware" in place already and see if any of that can be leveraged to correlate transactions across tiers.

过期情话 2024-10-14 14:25:30

不会。根据您的应用程序的规模,您还有很多工作要做。

为了使进度报告正常工作,您需要执行工作的代码以在工作单元完成时引发事件。该事件需要在 UI 层处理并更新进度指示器。

一个好的起点是研究使用BackgroundWorker(MSDN 上有一个示例 - http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx)。一旦您熟悉了BackgroundWorker,您应该能够更好地决定需要对应用程序进行哪些更改。

No. Depending on how large your application is, you have a lot of work ahead of you.

For progress reporting to work, you need the code which is performing the work to raise events when a unit of work is completed. That event needs to be handled at the UI layer and progress indicators updated.

A good place to start would be to look into using BackgroundWorker (there is an example on MSDN here - http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx). Once you're familiar with the BackgroundWorker you should be in a better position to decide which changes you need to make to your application.

猫弦 2024-10-14 14:25:30

您可以修改服务器代码,以便它在服务器端更新进度信息(不更改函数签名),然后有一个单独的方法可以单独查询此信息。

这将允许您改进对进度的支持,而不会对现有的服务器调用产生任何影响,只需在 UI 上添加一个新的后台线程,在长时间运行的任务正在进行时检查更新的进度信息。

编辑:我想同样的方法也适用于客户端中发生的任务。但是,这里也可以使用静态进度指示器类。

You could modify the server code so that it updates progress information at the server end (without changing function signatures), and then have a separate method that can query this information separately.

This would allow you to retrofit support for progress without having any impact whatsoever upon your existing calls to the server, just add a new background thread on the UI checking for updated progress information while a long running task is underway.

Edit: I guess the same approach would work for tasks that take place in the client. But still, a static progress indicator class could be used here too.

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