**** sorry about the length of the message. If you can't read the
whole thing and still willing to help, read the last 2 paragraphs where
the main problem is described. The introduction story is mentioned to,
as much clear as possible, give a picture in what environment the
problems rise****
Hello experts!
I would appreciate if you can address this problem I have and give a
hint what could be wrong.
It's a Windows Form application in VB.NET that uses shdocvw.dll to
automate internet browsing. I use InternetExplorer class from this
library. Navigation, browsing, setting the field values on the page,
submitting the forms and collecting the information is supposed to
happen all the time, in the loop. Once there are no more requests,
program will shut down. Let's call this app. the "worker".
This part works fine. Also I need to control this application from
within the other winform program, using .NET Remoting. For example, two
typical tasks would be query the information (like current state) and
close (force the shutdown of) the "worker". Let's call this app.
the "foreman". So "foreman" controls the execution of multiple
"worker" instances.
Because of the "worker" might be interrupted in it's job by
"foreman", I figured I should put it's main execution in the
background thread. So loop is executing in the bkg. thread and during
that time the .NET Remoting call for querying the info works fine.
Whatever the "worker" is doing, it's internal browser busy
navigating or idle, this call works. But when the "foreman" tries
to send the command for shutdown, most often the problems rise, usually
the COMException. The request to shutdown works like this:
"foreman" sends the .NET Remoting request to the "worker" and
the "worker" executes the simple Me.Close (since it's the winform
app). Then in the Window_Closing event handler some cleanup needs to be
done, first stop the browsing if currently in browsing mode, then
logout from the website, etc. As I understand, .NET Remoting call will
create a separate thread in the "worker" app, so the problems that
occur have something to do with multithreading and COM.
Since the error message wasn't always the same and the behavior not
unique every time, it's hard for me to describe what exactly happen.
Especially because multiple apps are executing and I can't debug them
all at the same time. Therefore I experiment with the "worker" only
and I managed to get the same error every time, that I'll describe
here. I hope it hapens for the same reason (multithreading with COM in
it) so if you give me a good advice, I'll probably be able to apply
it in the multi-app mode.
So here it is, very shortly:
"worker" processes the requests in a loop, internal IE object is
browsing, everything happens in a background thread. When all the work
is done, "worker" calls Me.Close on itself, this command still
happens in the bkg. thread. But once the Window_Closing ev. handler
starts executing, I notice this happens in a new thread. OK, that makes
sense, but it seems it causes the problems, because from this thread
some more IE browsing needs to be done, namely the logout from the
website. But as soon as the IE is invoked, even to access it's
Document property (not even to perform the action), the COM Exception
rises. I wonder why??? It's true that the COM object is accessed from
another thread, but at this moment IE is idle, it's not browsing or
doing anything. Maybe I need to mention, IE object is not even created
in the main bkg. thread, but during the initialization, in the form's
constructor.
And maybe most important, the COM Exception message:
"System.Runtime.InteropServices.COMException:
An outgoing call cannot be made since the application is dispatching an
input-synchronous call."
Please give a hint how to work-around this problem. Thanks a lot!
Shone