Mike23 said:
I'm aware of the details
Trying to keep this simple (I cross-posted to ASP.NET BTW but it may be a
simple threading issue which is why I posted to C# as well). There's a
well-known ASP.NET method called "Page_Load()" that every ASP.NET developer
is familiar with it. It's invoked by the system (on a web server) when a web
page is requested (to load the requested page). On this thread I'm calling
"System.Web.Services.Protocols.SoapHttpClientProtocol.InvokeAsync()" which I
just discovered after doing some digging around (the class I'm using is from
MSFT - it's a derivative of the latter class).
Unfortunately, the documentation for
SoapHttpClientProtocol.InvokeAsync() is almost non-existent. However,
it definitely looks very ASP.NET-specific. Browsing through the class
information, I'm not even convinced that InvokeAsync() is strictly a
threading-related method, as it appears to relate to client/server
invocation (i.e. invocation of a method via proxy).
The callback is being passed
via the 3rd arg to this function. Once I pass it, the function returns
immediately. I expected my callback to be invoked on another thread at this
point (it's thread safe) but not the same thread where "InvokeAsync()" is
called from.
What gave you that expectation?
That thread is blocked instead waiting for the callback to
complete its work.
What is the point of using an asynchronous method, only to sit and block
until it's done? Why not just call the synchronous version instead?
Note that in other contexts, doing that sort of thing can cause a _real_
deadlock. For example, in a Forms application, if you call
Control.BeginInvoke() from the owning thread, and then immediately after
the call block on something like ManualResetEvent.WaitOne(), your
program will deadlock.
Sounds like you might be getting off lucky, just having your callbacks
delayed, rather than blocked completely.
I have a "ManualResetEvent" set up that the callback
thread will signal when done. I'll have to take a closer look at this
"InvokeAsync()" method to see what it really does.
That sounds like a good idea to me. I think it's always a very good
idea to not write code that calls a method until you know what the
method really does.
It's indicated because that's the way an STA thread works
Well, you should see the immediate fallacy in that conclusion then.
[...]
Agreed, it could very well be some ASP.NET issue. But a thread is a thread
so it's unclear what the problem is.
But that's not true. If you're writing an ASP.NET program, it's not
strictly true that "a thread is a thread". ASP.NET has all sorts of
extra client/server proxying/marshaling/messaging/whatever that does
exist in a normal single-process, single-computer implementation.
Sounds to me like the starting point here is to find something that does
a good job describing what the InvokeAsync() method really does and why
a program would use it. I suspect it doesn't do what you seem to think
it does, at least not precisely (one hopes it has _something_ to do with
asynchronous invocation of code, but there are lots of different ways
that can happen...you can't just assume one particular implementation).
Pete