简体   繁体   English

ASP.Net / C#4.5 —异步处理—异步等待

[英]ASP.Net / C# 4.5 — Async Processing — Async Await

I am looking for some direction on what is the best route I should go with this. 我正在寻找什么方向,这是我应该走的最佳路线。 I have posted a few times, going off of some recommended design patterns. 我已经发布了几次,讨论了一些推荐的设计模式。 I have not really received a good direction based on what I am trying to accomplish. 根据我要完成的工作,我还没有真正得到好的指导。 I am new to working with Async Processing, and would appreciate some pointers in the right direction. 我是异步处理新手,并且希望您能向正确的方向提出一些建议。 So far, on one of my previous post I have been called ignorant because I requested code samples. 到目前为止,在我以前的一篇文章中,我被称为无知的,因为我要求提供代码示例。 Please understand I have been reading everything, and trying everything I can find on the internet. 请理解我一直在阅读所有内容,并尝试着可以在互联网上找到的所有内容。 Needless to say there are a LOT of different directions I could go with this, and I am not sure which one is the best. 不用说,我可以采用很多不同的方向,而且我不确定哪个是最好的。

I will explain what I am trying to do, at a high level, and if anyone out there can PLEASE help me by pointing me in the right direction I would appreciate it. 我将在较高的级别上解释我想做的事情,如果有任何人可以向我指出正确的方向来帮助我,我将不胜感激。 Also, if anyone can point me to some code samples, I would love that. 另外,如果有人可以指出一些代码示例,我也很乐意。 I do not mind reading the material, but it makes a lot more sense if I can see code to follow along with what it is saying. 我不介意阅读这些材料,但是如果我能看到遵循其说明的代码,那将变得更加有意义。 Most of the documentation I have found has code samples, or partial code samples, and I have been doing my best to try to use what I have found to work with my specific need. 我发现的大多数文档都有代码示例或部分代码示例,并且我一直在尽力尝试使用发现的功能来满足我的特定需求。 So far, not much luck. 到目前为止,还没有太大的运气。 I will admit, when it comes to ASYNC processing, I guess I am ignorant. 我承认,当涉及到ASYNC处理时,我想我很无知。 :) :)

Anyway, here is what I am trying to accomplish. 无论如何,这就是我要完成的工作。 I am leaving out any specific technology that I may consider using to avoid the debate as to if what I am posting is out of date, or behind the times. 我遗漏了我可能考虑使用的任何特定技术,以避免争论我发布的内容是否过时或落后于时代。 I am looking for a point in the right direction, and I am open to whatever at this point. 我正在寻找一个朝着正确方向发展的观点,并且我对此开放。 I just need to get this working. 我只需要使这个工作。

Here is the basics of what I am needing to do 这是我需要做的基础

  1. I have an ASP.Net Web Site "Project" that I am working with. 我有一个正在使用的ASP.Net网站“项目”。
  2. I have a screen that is used to print reports using Active Reports 7. 我有一个屏幕,用于使用Active Reports 7打印报告。
  3. My task is to allow the user to click a "Print / Preview" button and fire off the report processing. 我的任务是允许用户单击“打印/预览”按钮并启动报告处理。
  4. While the report is running, I need to give the user the ability to click a "Cancel" button and terminate the processing and return to the report screen. 运行报表时,我需要使用户能够单击“取消”按钮并终止处理并返回到报表屏幕。 (So the UI needs to be responsive during this time the report is processing so the user can click on the cancel button.) (因此,在处理报告的这段时间内,UI需要响应,以便用户可以单击“取消”按钮。)
  5. While the report is processing I need to display a popup message to indicate the report is running. 在处理报告时,我需要显示一条弹出消息以指示该报告正在运行。
  6. When the report finishes processing, I need to hide this popup message, to indicate to the user the report is completed. 报告完成处理后,我需要隐藏此弹出消息,以向用户指示报告已完成。 Then I need to open the report to be viewed by the user. 然后,我需要打开要由用户查看的报告。 Currently this is a javascript function that we prepare during the report processing code that opens a new window and calls the report viewer. 当前,这是我们在报表处理代码期间准备的javascript函数,它将打开一个新窗口并调用报表查看器。 (So after the report has completed I need the ability to call a javascript function.) (因此,在报告完成后,我需要能够调用javascript函数。)

If anyone can kindly point me in the right direction I will be very thankful. 如果有人能指出我正确的方向,我将非常感激。 I do not mind doing the leg work and reading a mountain of documentation. 我不介意进行腿部工作和阅读大量文档。 I just need to be able to know what I am looking at will provide me with the above functionality. 我只需要能够知道我正在寻找的内容即可为我提供上述功能。 Like I said earlier, ignorance or not, if I can get some sample working code (not asking anyone to code this for me, just some code I can step through and help to understand what is happening) it would help a lot. 就像我之前说的,不管是否了解,如果我可以获得一些示例工作代码(不要求任何人为我编写代码,只需我可以逐步通过一些代码来帮助理解正在发生的事情),它将大有帮助。

Thanks you in advance for your time and consideration. 预先感谢您的时间和考虑。

Since you want some operation to happen at the server side along with the UI responding and showing progress. 因为您希望在服务器端进行一些操作以及UI响应并显示进度。 Showing progress of the event. 显示事件的进度。 I would suggest using Signalr.Net. 我建议使用Signalr.Net。

http://signalr.net/ http://signalr.net/

http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr

This is a realtime web api and with this you can create a hub which has functions say "ProcessReport" and "cancelProcessing" you can call this from javascript while connection is open on click of the button and show the progress popup with a cancel button. 这是一个实时的Web api,您可以使用它创建一个具有“ ProcessReport”和“ cancelProcessing”功能的集线器,在单击该按钮时打开连接时可以从javascript调用它,并显示带有取消按钮的进度弹出窗口。 Have a client event registered with the hub in js say "updatestatus" which can be called from the server to close the popup and eventually close the signalr connection, once the operation is finished. 在操作完成后,在js中用集线器注册一个客户端事件,说“ updatestatus”,可以从服务器调用该事件以关闭弹出窗口并最终关闭信号器连接。 And similarly in the popup cancel click you can again call the hub function cancelProcessing and perform your cancellation and call back with updateStatus. 同样,在弹出的取消单击中,您可以再次调用集线器功能cancelProcessing并执行取消操作,并使用updateStatus进行回调。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM