Microsoft Help: IEExe.exe and STA

P

pfurb

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

Chris Botha

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
 
P

pfurb

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

pfurb

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?
 
P

Paul Hetherington

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
 
C

Chris Botha

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 said:
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
 
S

Sankar Nemani

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

Chris Botha said:
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 said:
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.
app,
and
 
J

Jeff B.

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,087
Latest member
JeremyMedl

Latest Threads

Top