多线程使用网络应用程序 [英] Use of Multithreading In web apps

查看:191
本文介绍了多线程使用网络应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用调用Oracle报表应用程序服务器和我有一个URL来调用报告。当报告被称为服务器将其转换成PDF但当报告包含大量数据需要花费大量的时间来加载。我想在asp.net这样做,当我打电话,报告它的URL打开PDF文件,并​​拷贝到我的网络文件夹的根。下一次,当我把它打开PDF文件,并​​创建于后端下一次调用一个新的PDF文件。该URL

我有此功能来下载文件

 子DownloadFile_Sap()
        昏暗remoteuri作为字符串=htt​​p://appsrv01.shakarganj.com.pk:7778/reports/rwservlet?reptest&report=sap_dashboard
        昏暗的文件名的String =使用Server.Mappath(〜/文件/ rwservlet_reptest&安培;报告= sap_dashboard.pdf)
        昏暗mywebClient作为新Net.WebClient()
        mywebClient.DownloadFile(remoteuri,文件名)
    结束小组

和我把它叫做上的LinkBut​​ton - code低于

 保护小组LinkBut​​ton1_Click(BYVAL发件人为对象,BYVAL E上System.EventArgs)把手LinkBut​​ton1.Click
    ClientScript.RegisterStartupScript(Me.GetType(),打开文件,window.open('http://202.125.144.34:83/Files/rwservlet_reptest&report=sap_dashboard.pdf');,真)
        DownloadFile_Sap()    结束小组

但是,当我呼吁链接按钮这种方法它得到了它在下载文件的同时。我能做些什么,这样的链接按钮调用从文件夹中的第二个文件并下载与后端的文件?

链接按钮code是这里

 < ASP:LinkBut​​ton的ID =Linkbutton1=服务器一项PostBackUrl =〜/文件/ rwservlet_reptest&安培;报告= sap_dashboard.pdf的OnClick =DownloadFile_Sap>的LinkBut​​ton&LT ; / ASP:LinkBut​​ton的>


解决方案

多线程在asp.net web应用程序是不是一个好主意。

您已经在 IIS线程池来源有限,如果你试图在这样的操作中使用此,
你会对生产造成了严重的问题。

所以,你可以做到这一点,分裂为 Windows服务。请在Windows服务应用程序的所有昂贵的操作。使通过 SQL表您的Web应用程序和窗口服务的应用程序之间的通信。

编辑:

下面这个路径:

您将需要的Visual Studio项目结果
1 - 你的Web应用程序(你必须alrady话)结果
2 - 新项目将运行Windows服务。

然后,你将有一个包含SQL表:结果
REPORT_NAME,Ready_Flag

从Web应用程序您填写REPORT_NAME结果
从Windows服务报告是prepared并设置Ready_Flag为true结果
您可以从Web应用程序Ready_Flag查询,如果设置为true,一旦它是真实的,
你提供给客户端

I am using an Application server for calling Oracle Reports and I have a URL to call the report. When the report is called the server converts it into PDF but when report contains large data it takes a lot of time to load. I want to do in asp.net that when I call the report url it opens the PDF file and copies it into the root of my web folder. The next time when I call the URL it opens the PDF file and creates a new PDF on backend for next call.

I have made this function to download file

Sub DownloadFile_Sap()
        Dim remoteuri As String = "http://appsrv01.shakarganj.com.pk:7778/reports/rwservlet?reptest&report=sap_dashboard"
        Dim filename As String = Server.MapPath("~/Files/rwservlet_reptest&report=sap_dashboard.pdf")
        Dim mywebClient As New Net.WebClient()
        mywebClient.DownloadFile(remoteuri, filename)
    End Sub

and I called it on linkbutton - code is below

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
    ClientScript.RegisterStartupScript(Me.GetType(), "openfile", "window.open('http://202.125.144.34:83/Files/rwservlet_reptest&report=sap_dashboard.pdf');", True)
        DownloadFile_Sap()

    End Sub

But when I call this method on link button it gets same time as it got on download file. What can I do so that the Link button calls the file from the folder in a second and downloads the file on the backend?

Link button code is here

 <asp:linkbutton ID="Linkbutton1" runat="server" PostBackUrl="~/Files/rwservlet_reptest&report=sap_dashboard.pdf" OnClick="DownloadFile_Sap"  >LinkButton</asp:linkbutton>

解决方案

Multithreading in asp.net web application is not a good idea.

You have limited source on IIS thread pool and if you try to use this in a such operation, you will have serious problems on production.

So what you can do it, split to Windows service. Do all expensive operations on windows service application. Make the communication between your web app and windows service app through sql table.

EDIT:

Here the path for this:

You will have to visual studio projects
1- your web app(you have alrady it)
2- new project that will run as windows service.

Then you will have sql table containing:
Report_Name, Ready_Flag

From web app you fill Report_Name
From windows service report is prepared and set Ready_Flag to true
You can query from web app Ready_Flag if set true, once it is true, you serve to client

这篇关于多线程使用网络应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆