Microsoft Help: IEExe.exe and STA

Discussion in 'ASP .Net' started by pfurb, Jan 19, 2004.

  1. pfurb

    pfurb Guest

    Hi.
    We are developing a windows application that is deployed using
    No-Touch-Deployment (with Full-trust).
    I have implemented Axhost handling microsoft web browser control
    SHDocvw.dll.
    In order to make it work i have to start the application in
    partmentState.STA. So I am creating a new thread in main(), explicitly
    specifying STA, otherwise I can not get the Web browser control to
    work.

    In the application I also use a System.Windows.Forms.Timer. Everything
    works fine when I run it in debug or release mode from my disk, but
    when I deploy the application using NTD the Timer causes an error. But
    the error does not occur until the application closes. If I remove the
    timer, there is no problem.

    I have had a lot of problems with ApartmentState.STA and
    No-Touch-Deployment. In some circumstances Control.Invoke do not
    marshal the thread correctly, which causes the application to get an
    security exception. The stacktrace saying something about
    InvokeMarshaled... Maybe the timer-problem is also caused by incorrect
    Invoke Marshaling.

    I hope to find a workaround for these problem, which I think is a bug
    inside IEExe.exe. At least to get the Timer to work. There must be a
    way to handle No-Touch-Deployment and ApartmentState.STA!!!

    If someone could help me with this I would be very grateful.
     
    pfurb, Jan 19, 2004
    #1
    1. Advertising

  2. pfurb

    Chris Botha Guest

    I had a similar problem with VS.NET 2002 and a no-touch-deployment app, is
    that what you are using?
    I think all your problems should go away if the main app runs in STA and you
    don't use threads to do the UI stuff.
    To make the main app run in STA, inside your 1st form (if it is called
    Form1), do something like

    <STAThread()> _
    Public Shared Sub main()
    Dim fff As Form1 = New Form1
    fff.ShowDialog()
    End Sub

    Just to make sure the app is running in STA, in the Form_Load event of the
    main form, do a
    MsgBox(System.Threading.Thread.CurrentThread.ApartmentState)
    and it should return a zero (0 = STA)

    Let us know if this solves the problem

    "pfurb" <> wrote in message
    news:...
    > Hi.
    > We are developing a windows application that is deployed using
    > No-Touch-Deployment (with Full-trust).
    > I have implemented Axhost handling microsoft web browser control
    > SHDocvw.dll.
    > In order to make it work i have to start the application in
    > partmentState.STA. So I am creating a new thread in main(), explicitly
    > specifying STA, otherwise I can not get the Web browser control to
    > work.
    >
    > In the application I also use a System.Windows.Forms.Timer. Everything
    > works fine when I run it in debug or release mode from my disk, but
    > when I deploy the application using NTD the Timer causes an error. But
    > the error does not occur until the application closes. If I remove the
    > timer, there is no problem.
    >
    > I have had a lot of problems with ApartmentState.STA and
    > No-Touch-Deployment. In some circumstances Control.Invoke do not
    > marshal the thread correctly, which causes the application to get an
    > security exception. The stacktrace saying something about
    > InvokeMarshaled... Maybe the timer-problem is also caused by incorrect
    > Invoke Marshaling.
    >
    > I hope to find a workaround for these problem, which I think is a bug
    > inside IEExe.exe. At least to get the Timer to work. There must be a
    > way to handle No-Touch-Deployment and ApartmentState.STA!!!
    >
    > If someone could help me with this I would be very grateful.
     
    Chris Botha, Jan 19, 2004
    #2
    1. Advertising

  3. pfurb

    pfurb Guest

    Thanks for your reply.
    No the code you presented does not solves the problem. When I use an
    ActiveX component and No-Touch-Deployment I have to explicitly set the
    thread in ApartmentState.STA. Like this...

    [STAThread]
    static void Main()
    {
    Thread newThread = new Thread(new ThreadStart(RunMain));
    newThread.ApartmentState = ApartmentState.STA;
    newThread.Start();
    }

    static void RunMain()
    {
    Application.Run(new Form1());
    }

    Otherwise I can not get it to work together with an ActiveX component
    using AxHost. (For example: Try deploying this code using NTD and
    Full-trust http://groups.google.se/groups?hl=sv&lr=&ie=UTF-8&selm=en#UikVlBHA.696@tkmsftngp05).
    But when I start the application like above the
    System.Windows.Forms.Timer causes an exception. When the application
    closes it will get an exception due to the timer, but the exception is
    also caused by the fact that the timer tries to read information from
    the users disk. (Which is ok in Full-Trust and NTD without explicitly
    setting ApartmentState.STA). It is almost like the Timer fails to
    marshal to the main application thread. If I create a customized timer
    using thread it will not work at all.

    I guess this is a bug in IEExe, but there is got to be a workaround. I
    really hope that someone could explain what is happening and why and
    how to solve it.

    Best Regards.

    > I had a similar problem with VS.NET 2002 and a no-touch-deployment app, is
    > that what you are using?
    > I think all your problems should go away if the main app runs in STA and you
    > don't use threads to do the UI stuff.
    > To make the main app run in STA, inside your 1st form (if it is called
    > Form1), do something like
    >
    > <STAThread()> _
    > Public Shared Sub main()
    > Dim fff As Form1 = New Form1
    > fff.ShowDialog()
    > End Sub
    >
    > Just to make sure the app is running in STA, in the Form_Load event of the
    > main form, do a
    > MsgBox(System.Threading.Thread.CurrentThread.ApartmentState)
    > and it should return a zero (0 = STA)
    >
    > Let us know if this solves the problem
     
    pfurb, Jan 20, 2004
    #3
  4. pfurb

    pfurb Guest

    After some time of testing I have found out that the Timer exception
    does not have anything to do with reading from disk. The Timer
    exception occurs due to the fact that it causes some UI operations. In
    this case the Timer function opens a form dialog when it detects some
    changes. This causes IEExe to error-report when it is closed.

    So I guess I am closer to the problem. But does anyone have a solution
    or similar experiences?
     
    pfurb, Jan 20, 2004
    #4
  5. You might be causing a security exception.
    I know that there are some UI operations that are not allowed in partially
    trusted contexts. For example. Control.Focus(); will throw as Security
    Exception when running Partially Trusted.
    Wrap your timer event in a Try..Catch block and output the
    Exception.StackTrace() that might help narrow the problem
    -
    Paul
    "pfurb" <> wrote in message
    news:...
    > After some time of testing I have found out that the Timer exception
    > does not have anything to do with reading from disk. The Timer
    > exception occurs due to the fact that it causes some UI operations. In
    > this case the Timer function opens a form dialog when it detects some
    > changes. This causes IEExe to error-report when it is closed.
    >
    > So I guess I am closer to the problem. But does anyone have a solution
    > or similar experiences?
     
    Paul Hetherington, Jan 20, 2004
    #5
  6. pfurb

    Chris Botha Guest

    I am just thinking that I am using the Web browser control with no-touch
    deployment and it works (no threads involved opening forms, which I think
    causes your problem).
    As a test, do you know how to customize the toolbox and how to get the Web
    browser control on it, and then drag it onto a form?
    Then to test the concept, rather than using AxHost, create a simple app with
    NO threads and a Web browser control on the form and on the form_load
    navigate to some site and then no-touch deploy the app.


    "pfurb" <> wrote in message
    news:...
    > Thanks for your reply.
    > No the code you presented does not solves the problem. When I use an
    > ActiveX component and No-Touch-Deployment I have to explicitly set the
    > thread in ApartmentState.STA. Like this...
    >
    > [STAThread]
    > static void Main()
    > {
    > Thread newThread = new Thread(new ThreadStart(RunMain));
    > newThread.ApartmentState = ApartmentState.STA;
    > newThread.Start();
    > }
    >
    > static void RunMain()
    > {
    > Application.Run(new Form1());
    > }
    >
    > Otherwise I can not get it to work together with an ActiveX component
    > using AxHost. (For example: Try deploying this code using NTD and
    > Full-trust

    http://groups.google.se/groups?hl=sv&lr=&ie=UTF-8&selm=en#UikVlBHA.696@tkmsftngp05).
    > But when I start the application like above the
    > System.Windows.Forms.Timer causes an exception. When the application
    > closes it will get an exception due to the timer, but the exception is
    > also caused by the fact that the timer tries to read information from
    > the users disk. (Which is ok in Full-Trust and NTD without explicitly
    > setting ApartmentState.STA). It is almost like the Timer fails to
    > marshal to the main application thread. If I create a customized timer
    > using thread it will not work at all.
    >
    > I guess this is a bug in IEExe, but there is got to be a workaround. I
    > really hope that someone could explain what is happening and why and
    > how to solve it.
    >
    > Best Regards.
    >
    > > I had a similar problem with VS.NET 2002 and a no-touch-deployment app,

    is
    > > that what you are using?
    > > I think all your problems should go away if the main app runs in STA and

    you
    > > don't use threads to do the UI stuff.
    > > To make the main app run in STA, inside your 1st form (if it is called
    > > Form1), do something like
    > >
    > > <STAThread()> _
    > > Public Shared Sub main()
    > > Dim fff As Form1 = New Form1
    > > fff.ShowDialog()
    > > End Sub
    > >
    > > Just to make sure the app is running in STA, in the Form_Load event of

    the
    > > main form, do a
    > > MsgBox(System.Threading.Thread.CurrentThread.ApartmentState)
    > > and it should return a zero (0 = STA)
    > >
    > > Let us know if this solves the problem
     
    Chris Botha, Jan 20, 2004
    #6
  7. DOes anyone know how to detect if .NET exists on the client machine and
    redirect them to a download page?

    "Chris Botha" <> wrote in message
    news:...
    > I am just thinking that I am using the Web browser control with no-touch
    > deployment and it works (no threads involved opening forms, which I think
    > causes your problem).
    > As a test, do you know how to customize the toolbox and how to get the Web
    > browser control on it, and then drag it onto a form?
    > Then to test the concept, rather than using AxHost, create a simple app

    with
    > NO threads and a Web browser control on the form and on the form_load
    > navigate to some site and then no-touch deploy the app.
    >
    >
    > "pfurb" <> wrote in message
    > news:...
    > > Thanks for your reply.
    > > No the code you presented does not solves the problem. When I use an
    > > ActiveX component and No-Touch-Deployment I have to explicitly set the
    > > thread in ApartmentState.STA. Like this...
    > >
    > > [STAThread]
    > > static void Main()
    > > {
    > > Thread newThread = new Thread(new ThreadStart(RunMain));
    > > newThread.ApartmentState = ApartmentState.STA;
    > > newThread.Start();
    > > }
    > >
    > > static void RunMain()
    > > {
    > > Application.Run(new Form1());
    > > }
    > >
    > > Otherwise I can not get it to work together with an ActiveX component
    > > using AxHost. (For example: Try deploying this code using NTD and
    > > Full-trust

    >

    http://groups.google.se/groups?hl=sv&lr=&ie=UTF-8&selm=en#UikVlBHA.696@tkmsftngp05).
    > > But when I start the application like above the
    > > System.Windows.Forms.Timer causes an exception. When the application
    > > closes it will get an exception due to the timer, but the exception is
    > > also caused by the fact that the timer tries to read information from
    > > the users disk. (Which is ok in Full-Trust and NTD without explicitly
    > > setting ApartmentState.STA). It is almost like the Timer fails to
    > > marshal to the main application thread. If I create a customized timer
    > > using thread it will not work at all.
    > >
    > > I guess this is a bug in IEExe, but there is got to be a workaround. I
    > > really hope that someone could explain what is happening and why and
    > > how to solve it.
    > >
    > > Best Regards.
    > >
    > > > I had a similar problem with VS.NET 2002 and a no-touch-deployment

    app,
    > is
    > > > that what you are using?
    > > > I think all your problems should go away if the main app runs in STA

    and
    > you
    > > > don't use threads to do the UI stuff.
    > > > To make the main app run in STA, inside your 1st form (if it is called
    > > > Form1), do something like
    > > >
    > > > <STAThread()> _
    > > > Public Shared Sub main()
    > > > Dim fff As Form1 = New Form1
    > > > fff.ShowDialog()
    > > > End Sub
    > > >
    > > > Just to make sure the app is running in STA, in the Form_Load event of

    > the
    > > > main form, do a
    > > > MsgBox(System.Threading.Thread.CurrentThread.ApartmentState)
    > > > and it should return a zero (0 = STA)
    > > >
    > > > Let us know if this solves the problem

    >
    >
     
    Sankar Nemani, Jan 20, 2004
    #7
  8. pfurb

    Jeff B. Guest

    > DOes anyone know how to detect if .NET exists on the client machine and
    > redirect them to a download page?


    IE will report the version number of any installed .NET Framework version(s)
    in the "appVersion" property of the "navigator" object. Here is a small
    test html page that will display this value:

    --------------------------
    <html>
    <head>
    <title>.NET CLR Version Test</title>
    <script language=JavaScript>
    function showVersion() {
    txtVersion.outerText = navigator.appVersion;
    }
    </script>
    </head>
    <body onLoad="showVersion();">
    <center>IE version is: <span id=txtVersion></span></center>
    </body>
    </html>
    --------------------------

    You could parse the "appVersion" value and if the CLR information is not
    present, then you could redirect with instructions to download the .NET
    Framework.

    I haven't tested this with Netscape or any other browsers so I don't know if
    they report any of this information. However, if you're creating NTD apps,
    then you have to use IE anyway.

    Hope this helps.

    --
    Thanks, Jeff
     
    Jeff B., Jan 20, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pfurb
    Replies:
    0
    Views:
    548
    pfurb
    Jan 21, 2004
  2. Charles A. Lackman
    Replies:
    1
    Views:
    1,458
    smith
    Dec 8, 2004
  3. Crimson_M

    Design Flow: STA to Synthesis

    Crimson_M, Sep 8, 2003, in forum: VHDL
    Replies:
    1
    Views:
    831
    Brian Drummond
    Sep 9, 2003
  4. SpamProof
    Replies:
    0
    Views:
    654
    SpamProof
    Oct 21, 2003
  5. Anthony Jones

    STA object in Session and Thread Affiliation

    Anthony Jones, Feb 6, 2006, in forum: ASP General
    Replies:
    12
    Views:
    249
    Anthony Jones
    Feb 11, 2006
Loading...

Share This Page