2

同じリモート Web サイトを対象とする単一の winforms アプリ プロセスから複数のブラウザー (aXWebBrowser コントロール) をプログラムで制御する方法はありますが、各ブラウザーはリモート サイトとの独自のセッション スコープ内にありますか?

目標 - Web サイトの使用を自動化するアプリケーションを構築します。目標は、アプリケーションが同じ Web サイトでブラウザーと対話する最大 5 人のユーザーの作業を行うことです。

明らかな課題 - 各ブラウザ インスタンスは、リモート Web サイトから送信された「セッション」データを共有します。その結果、実際の複数の人間のユーザーが行うように、さまざまなブラウザーが動作できなくなります。いくつの異なる aXWebBrowser コントロールがインスタンス化されても、それぞれがそのセッション コンテキストを失い、最後/最新/最後にインスタンス化されたブラウザーによって確立されたセッション コンテキストを共有します。言い換えれば、最後に起動されたコントロールは、それ以前のコントロールの確立されたセッション コンテキストを破棄します。

既に試し た - 次のレジストリ キーのいずれかを 'hkcu\software\microsoft\internet explorer\main' に追加します: TabProcGrowth=DWORD:0、FrameMerging=DWORD:0、SessionMerging=DWORD:0。デスクトップ アイコン (アプリの外部) から IE8 を起動すると、これは正常に動作し、IE8 は希望どおりに動作します。ただし、axWebBrowser コントロールを使用してアプリケーションを実行すると、レジストリ設定が axWebBrowser コントロールに影響を与えないように見えます。アプリケーションの外部で望ましくない動作を確認する他の方法には、IE8 の [ファイル] メニューで [新しいセッション] をクリックし、-nomerge を指定して iexplore.exe を起動する方法があります。axWebBrowser コントロールは通信に Wininet を使用するため、これらはアプリケーション内では機能しません。

制約 - aXWebBrowser コントロール (Internet Explorer ActiveX の自動化可能な Web ブラウザ) を使用して既に記述され、機能しているかなりのコードがあるため、理想的なソリューションでは、新しいコントロールでコードを書き直す必要はありません。- ソリューションが見つかった後、アプリケーションはブラウザ ウィンドウをワークステーション ユーザーに表示します。- winforms アプリケーション (.NET 2.0) がコントロールをホストしている - ブラウザーはすべて同じリモート Web サイトをターゲットにしています。

4

1 に答える 1

0

私が知る限り、各ブラウザが同じスレッドにロードされている限り、IEは常にそれらを同じセッションとして扱います。

この問題を回避するには、セッションごとに新しいスレッドと新しいウィンドウを作成しました。

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    private static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        //// How many test windows do we need to create.
        int numberOfClients = 5;
        System.Threading.Thread[] threads = 
            new System.Threading.Thread[numberOfClients];

        //// Create threads for each of the windows, and then start them.
        for (int i = 0; i < numberOfClients; i++)
        {
            threads[i] = new System.Threading.Thread(Program.StartTest);
            threads[i].SetApartmentState(System.Threading.ApartmentState.STA);
            //// Passing in the startup parameters for each each instance.
            threads[i].Start(new StartupParameters(i));
        }

        //// This will keep the application running until 
        ////  all the windows are closed.
        foreach (System.Threading.Thread thread in threads)
        {
            thread.Join();
        }
    }

    /// <summary>
    /// Starts the test form.
    /// </summary>
    /// <param name="state">
    /// The state object containing our startup parameters.
    /// </param>
    private static void StartTest(object state)
    {
        StartupParameters parameters = state as StartupParameters;
        YourTestForm yourTestForm = new YourTestForm();

        //// Set the needed parameters before we run the form.  
        //// Add your parameters here.
        yourTestForm.Text = string.Format("Test form {0}", parameters.Index);

        //// Run the test.
        Application.Run(yourTestForm);
    }
}

/// <summary>
/// Contains the startup parameters used to configure 
/// each new instance of the test form.
/// </summary>
public class StartupParameters
{
    /// <summary>
    /// Initializes a new instance of the <see cref="StartupPramitures"/> class.
    /// </summary>
    /// <param name="index">The index.</param>
    public StartupParameters(int index)
    {
        this.Index = index;
    }

    /// <summary>
    /// The index for this test form.
    /// </summary>
    public int Index { get; private set; }
}
于 2009-08-26T03:45:22.477 に答える