Alvin
Tue May 04 16:03:27 CDT 2004
>Mattias and I were talking in more *general* terms
ok
> It seems rather unlikely that just passing the context through a
> constructor makes any difference to it. Could you give two bits of
> code, one which doesn't go through a constructor and one which does, to
> illustrate the difference?
I've been trying to produce this for a while and cannot get it to fail.
Are you saying that if you access the
> context after it's gone "through" a constructor, you've got thread-safe
> access to it, but otherwise it always throws an exception? That really
> does sound highly unlikely.
I thought you hit upon something with this statement but I haven't been able
to confirm it with a test case for the longest while. I suspect it is the
meat of the issue but I am not able to demonstrate my theory effectively to
post anything.
What i am looking for, and am not able to produce yet, is an exception with
the following text
The type System.Web.HttpException
in Assembly System.Web, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a is not
marked as serializable
I'm trying to test the theory that the object is already gone which causes
access to fail, but I am not successfull. I can still access the object for
some time after the page is thru executing and i don't get the exception i
am looking for.
--
Regards,
Alvin Bruney
[ASP.NET MVP
http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here...
http://tinyurl.com/27cok
"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1b01fdcca2e4965798a83a@msnews.microsoft.com...
> <"Alvin Bruney [MVP]" <vapor at steaming post office>> wrote:
>> trying again...
>>
>> > No, Mattias was correct. He said that objects don't *generally* belong
>> > to one thread, and he was correct.
>>
>> No, you both are wrong. The main thread of control which initializes an
>> application owns the form and the controls on the form. It is the main
>> thread but it's still a thread. It *owns the forms and controls (windows
>> controls or otherwise) because it is the only sequential stream of
>> execution
>> which can interact with these components in a safe manner. All other
>> interactions by lesser threads will cause an exception - depending on
>> architecture. Consistence of these exceptions is entirely dependent on
>> the
>> underlying operating system architecture - NT behaves differently from
>> non-NT systems.
>
> Sorry, that's still talking about *specific* objects - namely UI
> objects. Mattias and I were talking in more *general* terms. Although
> specific classes (even a wide variety of them) may have thread
> affinity, it certainly isn't true that *all* do.
>
>> This is why GUI operations to these controls must be executed by the
>> thread
>> which owns these objects. That's not specific to webforms.
>
> No, it's specific to WinForms instead.
>
>> You must
>> control.invoke to carry out the operation in a thread safe manner. For
>> webforms, there is no control.invoke. So how is it to be done? Well thru
>> trial and error, I've found that a reference must be passed in using the
>> code below. I'd like to know why this works since technically it really
>> should not.
>
> It seems rather unlikely that just passing the context through a
> constructor makes any difference to it. Could you give two bits of
> code, one which doesn't go through a constructor and one which does, to
> illustrate the difference? Are you saying that if you access the
> context after it's gone "through" a constructor, you've got thread-safe
> access to it, but otherwise it always throws an exception? That really
> does sound highly unlikely.
>
> --
> Jon Skeet - <skeet@pobox.com>
>
http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too