user1720204
user1720204

Reputation: 11

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. Creating a thread gives me session time out on IIS. How do i create threads that can work fine on IIS?

Below is the code where iam created the thread.

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.

Upvotes: 1

Views: 537

Answers (2)

Franck LEVEQUE
Franck LEVEQUE

Reputation: 440

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.

If you want to open the dialog file on the client side you can do it in a similar way as was ActiveX objects.

You can find a msdn tutorial of how to do it at the following address but it only work in IE:

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

Upvotes: 1

CobaltBlue
CobaltBlue

Reputation: 354

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. 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. 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.

What if they are on a Linux box, or a Mac?

ASP.NET was created to solve this problem of creating interactive forms for IIS.

Hope this helps.

Upvotes: 0

Related Questions