简体   繁体   English

Web应用程序中的线程使托管在IIS 7上的会话超时

[英]threading in web application giving a session timed out when hosted on iis 7

In my asp.net application, iam using windows forms.dll to use some of the windows controls by creating a thread.This works fine in my system but is giving a session timeout when hosted on IIS. 在我的asp.net应用程序中,我使用Windows Forms.dll通过创建线程来使用某些Windows控件。这在我的系统中工作正常,但在IIS上托管时会导致会话超时。 Creating a thread gives me session time out on IIS. 创建线程使我在IIS上的会话超时。 How do i create threads that can work fine on IIS? 如何创建可以在IIS上正常运行的线程?

Below is the code where iam created the thread. 以下是iam创建线程的代码。

public string[] DisplayFileDialog()
    {
        string[] result = null;

        try
        {
            Thread objThread = new Thread(state =>{
                result = FnOpenFileDialog();
                // TODO: do something with the returned result
            });

            objThread.IsBackground = false;
            objThread.SetApartmentState(ApartmentState.STA);
            objThread.Start();
            objThread.Join();
            return result;

        }
        catch (Exception ex)
        {


            return result;
        }

 protected string[] FnOpenFileDialog()
    {
        IntPtr hdlr = GetForegroundWindow();

        WindowWrapper Mockwindow = new WindowWrapper(hdlr);

        OpenFileDialog fDialog = new OpenFileDialog();

        fDialog.Title = "Select Files";

        fDialog.Multiselect = true;
        fDialog.CheckFileExists = true;
        fDialog.CheckPathExists = true;

        System.Windows.Forms.DialogResult dr = fDialog.ShowDialog(Mockwindow);
        string[] filenames = fDialog.FileNames;
        return filenames;
    }

Thanks in advance. 提前致谢。

Your code is executed server side, which is why your stalled by a time out response. 您的代码在服务器端执行,这就是为什么您因超时响应而停滞了的原因。 Your main thread waits (objThread.Join) for the response of a dialog box opened on the server as you can't see it on the client side you never get a response. 您的主线程等待(objThread.Join)等待服务器上打开的对话框的响应,因为您无法在客户端看到它,因此永远也不会得到响应。

If you want to open the dialog file on the client side you can do it in a similar way as was ActiveX objects. 如果要在客户端打开对话框文件,则可以采用与ActiveX对象类似的方式来进行操作。

You can find a msdn tutorial of how to do it at the following address but it only work in IE: 您可以在以下地址找到有关如何执行此操作的msdn教程,但仅在IE中有效:

http://msdn.microsoft.com/fr-fr/magazine/cc301932(en-us).aspx http://msdn.microsoft.com/fr-fr/magazine/cc301932(zh-cn).aspx

If I'm understanding your question correctly, the answer is simply: You can't do that. 如果我正确理解了您的问题,那么答案很简单:您不能那样做。

Windows forms controls don't work in a browser. Windows窗体控件在浏览器中不起作用。 It works on your machine because the browser window is local, so the thread can attach to it and use it as a parent. 它可以在您的计算机上使用,因为浏览器窗口是本地的,因此线程可以连接到该窗口并将其用作父窗口。

The IIS process doesn't have a window, it only serves up text, images, and video files. IIS进程没有窗口,它仅提供文本,图像和视频文件。 You're essentially asking an IIS thread, running on some machine in a server room somewhere else, to connect to a browser's window on someone else's machine, and then start displaying Windows Forms controls on it. 您实质上是在要求IIS线程(该服务器在其他地方的服务器机房中的某台计算机上运行)连接到其他人的计算机上的浏览器窗口,然后开始在其上显示Windows Forms控件。

What if they are on a Linux box, or a Mac? 如果它们在Linux盒子或Mac上怎么办?

ASP.NET was created to solve this problem of creating interactive forms for IIS. 创建ASP.NET是为了解决为IIS创建交互式表单的问题。

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

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

相关问题 访问IIS上托管的Web应用程序 - Accessing web application hosted on IIS IIS上的请求超时 - Request timed out on IIS 在 IIS 8 上托管的 ASP.NET Web 应用程序上读取系统事件日志条目时访问被拒绝 - Access denied when reading system event log entries on ASP.NET web application hosted on IIS 8 尝试从IIS中托管的Web应用程序连接到具有命名管道端点的WCF服务时,没有端点侦听错误 - No endpoint listening error when trying to connect to a WCF service with named pipe endpoint from Web application hosted in IIS 从iis上托管的Web应用程序读取/写入共享驱动器中的文件 - Read/write files in shared drive from web application hosted on iis 从Linux Web应用程序中使用IIS托管的WCF服务 - Consuming IIS-hosted WCF Service from Linux Web Application 从IIS上托管的Web API打开WPF应用程序 - Open a WPF Application from Web API that is hosted on IIS 当一个MVC Web应用程序托管在由多个用户同时访问的服务器上时,应用程序和会话变量发生了什么? - What happened to application and session variables when one MVC web application hosted on a server accessed by multiple users at the same time? WCF应用程序在IIS7上托管时返回400错误请求 - WCF Application returning 400 Bad Request when hosted on IIS7 应用程序托管到IIS时的MS SQL Server连接问题 - MS SQL Server connectivity issue when application hosted to IIS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM