Showing posts with label basically. Show all posts
Showing posts with label basically. Show all posts

Saturday, March 24, 2012

this seems too simple, to be accurate

What are the drawbacks if any to this approach of not
using the gac for shared components... basically having a
central directory located outside of iis, that all web
applications have a virtual dir named bin pointing to this
dir. like below setup, all on each server in a farm

web site root one
vdir bin points to drive\sharedbin

web application a
vdir bin points to drive\sharedbin

web application b
vdir bin points to drive\sharedbin

web site root two
vdir bin points to drive\sharedbin

web application 2a
vdir bin points to drive\sharedbin

my thinking is that it would be easier/faster to deploy a
new assembly (and its config file, which entails copying
that through dos into the correct location, we read the
config file from the location of the dll) by only copying
to a directory instead of having to gac remove, gac
install, copy config file into dir

thanks, jimHi Jim Butler,

Thanks for using Microsoft Newsgroup Service. Based on your description,
you want to create a Virutal Directory named "bin" under each
WebApplication's root Virutal Directroy, the "bin" VD is specified to a
physical path which has some assemblies you want to share in many web
applicaitons. Is my understanding or you problem correct?

As this problem, I think it due to how the ASP.NET web application search
for assemblies when compiled the pages at runtime. By default, the ASP.NET
runtime will search for assemblies at the "bin" sub directoy certain
assemblies not found in GAC. However, the "bin" subdirectoy is the physical
sub directoy, not by virtual path. For example, if you create a sub Virtual
Directoy named "bin" under web app's root Virutal Directory and then put
all the assemblies need into it and delete the physical "bin" sub directory
created by default. When you run the web page, the ASP.NET runtime can't
locate those assemblies correctly. So I don't think it a proper way to
locate shared assemblies like this.

In dotnet, if you want to specifically locate some assemblies in some
different paths, there are serveral approachs:
1. using GAC, I think this is the most convenient and will provide strong
version control for you. But this'll force you to make the assembly
strong-named.

2. To use the confige file for dotnet application. In dotnet, you can
specify the locations for certain assemblies in applicatino's configure
files. For ASP.NET , you can add such configure infomation in the
web.config file.
For example:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myAssembly"
publicKeyToken="32ab4ba45e0a69a1"
culture="en-us" />
<codeBase version="2.0.0.0"
href="http://www.litwareinc.com/myAssembly.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration
For more detailed information on how to "Specifying an Assembly's
Location", you may refer the following article in MSDN:
http://msdn.microsoft.com/library/e...cifyingassembly
slocation.asp?frame=true

Please check out the preceding suggestions to see whether they are helpful.
If you have any questions on it, please feel free to let me know.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
thanks for the response, what you have surmised is exactly my
question/situation, we have all of our assemblies strong named, i will try
out #2 and let you know how it goes... i will first try the probing path,
then the dependent assembly route.

jim

"Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> wrote in message
news:nFPYRjQ0DHA.2628@.cpmsftngxa07.phx.gbl...
> Hi Jim Butler,
> Thanks for using Microsoft Newsgroup Service. Based on your description,
> you want to create a Virutal Directory named "bin" under each
> WebApplication's root Virutal Directroy, the "bin" VD is specified to a
> physical path which has some assemblies you want to share in many web
> applicaitons. Is my understanding or you problem correct?
> As this problem, I think it due to how the ASP.NET web application search
> for assemblies when compiled the pages at runtime. By default, the ASP.NET
> runtime will search for assemblies at the "bin" sub directoy certain
> assemblies not found in GAC. However, the "bin" subdirectoy is the
physical
> sub directoy, not by virtual path. For example, if you create a sub
Virtual
> Directoy named "bin" under web app's root Virutal Directory and then put
> all the assemblies need into it and delete the physical "bin" sub
directory
> created by default. When you run the web page, the ASP.NET runtime can't
> locate those assemblies correctly. So I don't think it a proper way to
> locate shared assemblies like this.
> In dotnet, if you want to specifically locate some assemblies in some
> different paths, there are serveral approachs:
> 1. using GAC, I think this is the most convenient and will provide strong
> version control for you. But this'll force you to make the assembly
> strong-named.
> 2. To use the confige file for dotnet application. In dotnet, you can
> specify the locations for certain assemblies in applicatino's configure
> files. For ASP.NET , you can add such configure infomation in the
> web.config file.
> For example:
> <configuration>
> <runtime>
> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
> <dependentAssembly>
> <assemblyIdentity name="myAssembly"
> publicKeyToken="32ab4ba45e0a69a1"
> culture="en-us" />
> <codeBase version="2.0.0.0"
> href="http://links.10026.com/?link=http://www.litwareinc.com/myAssembly.dll"/>
> </dependentAssembly>
> </assemblyBinding>
> </runtime>
> </configuration>
>
> For more detailed information on how to "Specifying an Assembly's
> Location", you may refer the following article in MSDN:
http://msdn.microsoft.com/library/e...cifyingassembly
> slocation.asp?frame=true
> Please check out the preceding suggestions to see whether they are
helpful.
> If you have any questions on it, please feel free to let me know.
>
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
Steven, i was able to get the probing path to work, but it needs the path to
be a physical path, and not a virtual directory (ie website\sharedbin worked
as long as it was an actual folder under the web site). I can't seem to get
the dependentassembly tag to work though. below is an excerpt from my
web.config file. Is there something missing/wrong?

<dependentAssembly>
<assemblyIdentity name="co.app.assembly"
publicKeyToken="thepublickeytoken"
culture="neutral" />
<codeBase version="1.0.0.1"
href=http://localwebserver/app/sharedbin/co.app.assembly.dll />
</dependentAssembly
where sharedbin is a virtualdirectory to c:\sharedbin
when accessing the page, i get FileNotFoundException, and directly after the
pre-bind state info, there is a message that states
Log: Policy not being applied to reference at this time (private, custom,
partial, or location-based assembly bind)

this makes it seem like it is ignoring what i have in my web.config, thus
giving the file not found error

thanks jim

"Jim Butler" <unos@.companyabc.com> wrote in message
news:uVdqSFU0DHA.484@.TK2MSFTNGP10.phx.gbl...
> thanks for the response, what you have surmised is exactly my
> question/situation, we have all of our assemblies strong named, i will try
> out #2 and let you know how it goes... i will first try the probing path,
> then the dependent assembly route.
> jim
> "Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> wrote in message
> news:nFPYRjQ0DHA.2628@.cpmsftngxa07.phx.gbl...
> > Hi Jim Butler,
> > Thanks for using Microsoft Newsgroup Service. Based on your description,
> > you want to create a Virutal Directory named "bin" under each
> > WebApplication's root Virutal Directroy, the "bin" VD is specified to a
> > physical path which has some assemblies you want to share in many web
> > applicaitons. Is my understanding or you problem correct?
> > As this problem, I think it due to how the ASP.NET web application
search
> > for assemblies when compiled the pages at runtime. By default, the
ASP.NET
> > runtime will search for assemblies at the "bin" sub directoy certain
> > assemblies not found in GAC. However, the "bin" subdirectoy is the
> physical
> > sub directoy, not by virtual path. For example, if you create a sub
> Virtual
> > Directoy named "bin" under web app's root Virutal Directory and then put
> > all the assemblies need into it and delete the physical "bin" sub
> directory
> > created by default. When you run the web page, the ASP.NET runtime can't
> > locate those assemblies correctly. So I don't think it a proper way to
> > locate shared assemblies like this.
> > In dotnet, if you want to specifically locate some assemblies in some
> > different paths, there are serveral approachs:
> > 1. using GAC, I think this is the most convenient and will provide
strong
> > version control for you. But this'll force you to make the assembly
> > strong-named.
> > 2. To use the confige file for dotnet application. In dotnet, you can
> > specify the locations for certain assemblies in applicatino's configure
> > files. For ASP.NET , you can add such configure infomation in the
> > web.config file.
> > For example:
> > <configuration>
> > <runtime>
> > <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
> > <dependentAssembly>
> > <assemblyIdentity name="myAssembly"
> > publicKeyToken="32ab4ba45e0a69a1"
> > culture="en-us" />
> > <codeBase version="2.0.0.0"
> > href="http://links.10026.com/?link=http://www.litwareinc.com/myAssembly.dll"/>
> > </dependentAssembly>
> > </assemblyBinding>
> > </runtime>
> > </configuration>
> > For more detailed information on how to "Specifying an Assembly's
> > Location", you may refer the following article in MSDN:
http://msdn.microsoft.com/library/e...cifyingassembly
> > slocation.asp?frame=true
> > Please check out the preceding suggestions to see whether they are
> helpful.
> > If you have any questions on it, please feel free to let me know.
> > Regards,
> > Steven Cheng
> > Microsoft Online Support
> > Get Secure! www.microsoft.com/security
> > (This posting is provided "AS IS", with no warranties, and confers no
> > rights.)
Hi Jim ,

Thank you for the response. As for the "dependentAssembly" method, I've
done some test on my side. It does can specify a certain location path for
the dotnet runtime to find the required assembly. For example, I made a
strong-named assembly "GenericComponent.dll" ,version "1.0.0.1", then in
the ASP.NET web application's web.config file, I set as below:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="GenericComponent"
publicKeyToken="003114443600b39f" culture="" /
<codeBase version="1.0.0.1"
href="F:\workspace\GenericComponent\bin\debug\GenericCom ponent.dll"
/>
</dependentAssembly
</assemblyBinding>
</runtime
<system.web>
...............

</system.web>
</configuration
When run the page which called the classes in the dll, it did found it. You
may try checking the Assembly's name version or keyToken attributes to see
whether they were set as the correct value.

In addition, as for the problem you mentioned at start that you want to use
a http web url such as "http://mysite/sharedbin/xxx.dll" to locate the
assembly, I think there'll some limits if you are using the ASP.NET1.1. In
DOTNET, if you specify a assembly's location via weburl in configuration
file, when running , the runtime will try to download the assembly from the
url. Also, every AppDomain have an property named "DisallowCodeDownload"
which determines whether such operation is permitted. It can be get via :
"System.AppDomain.CurrentDomain.SetupInformation.Di sallowCodeDownload".
However, this property is set as "true" by default in dotnet 1.1 and didn't
provide any setting to change it in web.config or machine.config file. So
if you want to use the http web url to locate the assembly, maybe you need
to use some workaround to download the assembly manually. For example, use
the "WebClient" class to download the assembly, or specify the asp.net web
application to use the framework1.0. Here is some kb for them:
http://support.microsoft.com/?id=820106

BTW, since to use the web url location will caused so many problems, would
you consider that use a normal file path such as
"c:\foldername\assembly.dll" to specify the "codeBase" of the assembly.
Thus, you also can let serveral different web applications to share the
same folder(with those public assemblies). You just need to set the path in
the <dependentAssembly> element within the web.config file.

Please check out the preceding suggestions. If you have any questions on
them, please feel free to let me know.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Steven, thanks again for the help,

i was able to get your sample to work, but only if i added a reference to
the dll (set its copy local to false, so it wouldn't already be in the bin
dir), and compiled the application. Here we are using src= instead of
codebehind and not precompiling.

so it works like this (on the aspx page)

<%@. Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb"
Inherits="WebApplication1.WebForm1"%>
and fails like this

<%@. Page Language="vb" AutoEventWireup="false" src="http://pics.10026.com/?src=WebForm1.aspx.vb"
Inherits="WebForm1"%>
with this error
Compiler Error Message: BC30002: Type 'GenericComponent' is not defined

any ideas as to why?

thanks again,

jim

"Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> wrote in message
news:DcZTcu10DHA.3564@.cpmsftngxa07.phx.gbl...
> Hi Jim ,
>
> Thank you for the response. As for the "dependentAssembly" method, I've
> done some test on my side. It does can specify a certain location path for
> the dotnet runtime to find the required assembly. For example, I made a
> strong-named assembly "GenericComponent.dll" ,version "1.0.0.1", then in
> the ASP.NET web application's web.config file, I set as below:
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
> <runtime>
> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
> <dependentAssembly>
> <assemblyIdentity name="GenericComponent"
> publicKeyToken="003114443600b39f" culture="" />
> <codeBase version="1.0.0.1"
> href="http://links.10026.com/?link=F:\workspace\GenericComponent\bin\debug\GenericCom ponent.dll"
> />
> </dependentAssembly>
> </assemblyBinding>
> </runtime>
> <system.web>
> ..............
> </system.web>
> </configuration>
> When run the page which called the classes in the dll, it did found it.
You
> may try checking the Assembly's name version or keyToken attributes to see
> whether they were set as the correct value.
> In addition, as for the problem you mentioned at start that you want to
use
> a http web url such as "http://mysite/sharedbin/xxx.dll" to locate the
> assembly, I think there'll some limits if you are using the ASP.NET1.1. In
> DOTNET, if you specify a assembly's location via weburl in configuration
> file, when running , the runtime will try to download the assembly from
the
> url. Also, every AppDomain have an property named "DisallowCodeDownload"
> which determines whether such operation is permitted. It can be get via :
> "System.AppDomain.CurrentDomain.SetupInformation.Di sallowCodeDownload".
> However, this property is set as "true" by default in dotnet 1.1 and
didn't
> provide any setting to change it in web.config or machine.config file. So
> if you want to use the http web url to locate the assembly, maybe you need
> to use some workaround to download the assembly manually. For example, use
> the "WebClient" class to download the assembly, or specify the asp.net web
> application to use the framework1.0. Here is some kb for them:
> http://support.microsoft.com/?id=820106
> BTW, since to use the web url location will caused so many problems, would
> you consider that use a normal file path such as
> "c:\foldername\assembly.dll" to specify the "codeBase" of the assembly.
> Thus, you also can let serveral different web applications to share the
> same folder(with those public assemblies). You just need to set the path
in
> the <dependentAssembly> element within the web.config file.
> Please check out the preceding suggestions. If you have any questions on
> them, please feel free to let me know.
>
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
Hi James,

Thank you for the prompt response. Based on the situation you described in
the reply, now the "file not found" exception is caused at the comiple
time(when the page is requested and the dotnet runtime compile the page
class), because you
specify the "Src" attribute in the page directive @.page.

In dotnet, when compile the code, the dotnet runtime will search the needed
assemblies from the GAC or the application directory or the "bin" sub
directory for ASP.NET web application. The "dependentAssebmly" attrribute
set in the application config file such as web.config" file:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="GenericComponent"
publicKeyToken="003114443600b39f" culture="" /
<codeBase version="1.0.0.1"
href="F:\workspace\GenericComponent\bin\debug\GenericCom ponent.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime
such setting is used for the runtime to find the assemblies that will be
used by some of the existing assemblies. As for your situation, you set the
page's "Src" attribute to let its page class be compiled when first
requested, the compiler have no information about the "denpendentAssebmly"
set in the web.config file, this is why the "file no exception" occured.

If you do think it very important to specify the "Src" attribute of the
page to dynamicaly compile page class, I recommend that you use the GAC to
provide the shared assemblies. Otherwise, you'd have to gather those
asseblies in the web application's sub "bin" directory.

Please check out my preceding suggestions. If you have any questions on it
or you have any further information on your problem, please feel free to
let me know.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Steven,

I understand that this entry is necessary so that the compiler will find the
already compiled web service assembly .dll file in the GAC, correct? If that
entry has to be made in the web.config file, then this file will be
necessary for each web page (virtual path) that I want to use that web
service, correct?
To avoid coping the web.config file into multiple directories or maintaining
those if I want to publish a new assembly for all the web sites, can I add a
certain entry to the e.g. machine.config? If that is possible, can you give
an example?

Your help on that is highly appreciated!!!
Thank you,
Wolfgang

"Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> wrote in message
news:PTC7I1B1DHA.2256@.cpmsftngxa07.phx.gbl...
> Hi James,
>
> Thank you for the prompt response. Based on the situation you described in
> the reply, now the "file not found" exception is caused at the comiple
> time(when the page is requested and the dotnet runtime compile the page
> class), because you
> specify the "Src" attribute in the page directive @.page.
> In dotnet, when compile the code, the dotnet runtime will search the
needed
> assemblies from the GAC or the application directory or the "bin" sub
> directory for ASP.NET web application. The "dependentAssebmly" attrribute
> set in the application config file such as web.config" file:
> <runtime>
> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
> <dependentAssembly>
> <assemblyIdentity name="GenericComponent"
> publicKeyToken="003114443600b39f" culture="" />
> <codeBase version="1.0.0.1"
> href="http://links.10026.com/?link=F:\workspace\GenericComponent\bin\debug\GenericCom ponent.dll"/>
> </dependentAssembly>
> </assemblyBinding>
> </runtime>
> such setting is used for the runtime to find the assemblies that will be
> used by some of the existing assemblies. As for your situation, you set
the
> page's "Src" attribute to let its page class be compiled when first
> requested, the compiler have no information about the "denpendentAssebmly"
> set in the web.config file, this is why the "file no exception" occured.
> If you do think it very important to specify the "Src" attribute of the
> page to dynamicaly compile page class, I recommend that you use the GAC to
> provide the shared assemblies. Otherwise, you'd have to gather those
> asseblies in the web application's sub "bin" directory.
> Please check out my preceding suggestions. If you have any questions on it
> or you have any further information on your problem, please feel free to
> let me know.
>
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
Finally!!!

I have been able to figure it all out.

After the DLL has been added to the GAC (you will need to create a strongly
typed DLL to be able to add your DLL to the Global Assembly Cache GAC), you
have to add the DLL manually to the machine.config file that is located
under:
%systemroot%\Microsoft.net\Framework\<versionnumber>\config

The lines to be added have to be added in the following structure: (This
example adds the WebCounter.dll)
<configuration>
<system.web>
<compilation debug="false" explicit="true" defaultLanguage="vb">
<assemblies>
<add assembly="WebCounter, Version=1.0.1480.30047, Culture=neutral,
PublicKeyToken=c434ff78305dda8b" />
</assemblies>
</compilation>
</system.web>
</configuration
Verson and PublicKeyToken can be retrieved from the GAC that is located
under:
%systemroot%\assembly
Locate your DLL that you have added to that store, and right click to check
the info in the properties.

BTW, a handy dandy idea is to add the following tool to your MS VS.NET
Development IDE:
(select menu "Tools" - "External Tools" - "Add")
Enter the following fields:
Title: "Create Assembly Ke&y File"
Command: "D:\Microsoft\Microsoft Visual Studio .NET
2003\SDK\v1.1\Bin\sn.exe" (needs to be adjusted to your drive and path for
sn.exe)
Arguments: "-k $(TargetDir)$(TargetName).snk"
Initital Directory: "$(TargetDir)"
Check the option: Output window (that will allow you to copy & paste the
output file after successful generation into the AssemblyKeyFile directive
of your AssemblyInfo.vb file.

From now on you will be able to select that command and the tool will create
the key pair file for you that will have to be added to the DLL project's
"AssemblyInfo.vb" file in the following line:
<Assembly:
AssemblyKeyFile("E:\Development\WebTools\WebCounter\obj\Release\Web Counter.s
nk")
Hope that this info will help somebody to save a lot of trouble. I wished
that info would be available as a knowledge base article on MSDN.

All the best,
Wolfgang Kaml

"Jim Butler" <unos@.companyabc.com> wrote in message
news:eqrAU6I1DHA.2888@.tk2msftngp13.phx.gbl...
> stephen,
> that is kinda what i figured, worth a thought and try, thanks for all the
> help anyway. we will probably automate the push into the gac of the
shared
> assemblies.
> thanks again,
> jim
>
> "Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> wrote in message
> news:PTC7I1B1DHA.2256@.cpmsftngxa07.phx.gbl...
> > Hi James,
> > Thank you for the prompt response. Based on the situation you described
in
> > the reply, now the "file not found" exception is caused at the comiple
> > time(when the page is requested and the dotnet runtime compile the page
> > class), because you
> > specify the "Src" attribute in the page directive @.page.
> > In dotnet, when compile the code, the dotnet runtime will search the
> needed
> > assemblies from the GAC or the application directory or the "bin" sub
> > directory for ASP.NET web application. The "dependentAssebmly"
attrribute
> > set in the application config file such as web.config" file:
> > <runtime>
> > <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
> > <dependentAssembly>
> > <assemblyIdentity name="GenericComponent"
> > publicKeyToken="003114443600b39f" culture="" />
> > <codeBase version="1.0.0.1"
> > href="http://links.10026.com/?link=F:\workspace\GenericComponent\bin\debug\GenericCom ponent.dll"/>
> > </dependentAssembly>
> > </assemblyBinding>
> > </runtime>
> > such setting is used for the runtime to find the assemblies that will be
> > used by some of the existing assemblies. As for your situation, you set
> the
> > page's "Src" attribute to let its page class be compiled when first
> > requested, the compiler have no information about the
"denpendentAssebmly"
> > set in the web.config file, this is why the "file no exception" occured.
> > If you do think it very important to specify the "Src" attribute of the
> > page to dynamicaly compile page class, I recommend that you use the GAC
to
> > provide the shared assemblies. Otherwise, you'd have to gather those
> > asseblies in the web application's sub "bin" directory.
> > Please check out my preceding suggestions. If you have any questions on
it
> > or you have any further information on your problem, please feel free to
> > let me know.
> > Steven Cheng
> > Microsoft Online Support
> > Get Secure! www.microsoft.com/security
> > (This posting is provided "AS IS", with no warranties, and confers no
> > rights.)

Thursday, March 22, 2012

Thread class and Session variable

Hi All,

I am trying to perform a non-CPU bound operation in an asynchronous fashion
using 'Thread' and a delegate. Basically, I am spawning a thread using
ThreadStart and Thread.

My non-CPU bound operation needs to have access to Session variables; Even
though I embedded the state information (which also includes the context
object) in an object and passed the object to the Thread , I am unable to
access the Session variables. The system throws a Null Object Reference error.

Since the thread that I am spawning is not from the CLR thread pool, it is
not able to access the Session variable. Am I right? How can a system thread
get access to the Session variables of the current HTTPRequest?

I hope I articulated my problem. If not, please let me know.

Any pointers will be appreciated!This example ( albiet in Visual Basic.NET ) seems to work ok. Im not sure
what you are doing differently , or if I have misunderstood you ?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim myThread As New Threading.Thread(AddressOf mySpawned)

Session("TestMe") = "Hello World"

myThread.Start()

End Sub

Private Sub mySpawned()

Dim s As String = Session("TestMe")

End Sub

"Diffident" <Diffident@.discussions.microsoft.comwrote in message
news:32A19AC0-DB0F-4120-8BF6-4E1539BEB0B7@.microsoft.com...

Quote:

Originally Posted by

Hi All,
>
I am trying to perform a non-CPU bound operation in an asynchronous
fashion
using 'Thread' and a delegate. Basically, I am spawning a thread using
ThreadStart and Thread.
>
My non-CPU bound operation needs to have access to Session variables; Even
though I embedded the state information (which also includes the context
object) in an object and passed the object to the Thread , I am unable to
access the Session variables. The system throws a Null Object Reference
error.
>
Since the thread that I am spawning is not from the CLR thread pool, it is
not able to access the Session variable. Am I right? How can a system
thread
get access to the Session variables of the current HTTPRequest?
>
I hope I articulated my problem. If not, please let me know.
>
Any pointers will be appreciated!
>
>


Hi OHM,

Thanks for your response.

Here is what I am trying to do (in C#):

=====

ThreadStart t = new ThreadStart(LongDBProcess)
// LongDBProcess is a time-consuming process
Thread ts = new Thread(t);
t.start(); //At this point, system thread will be created and not
the CLR thread

====

I need to have access to Session variables inside my LongDBProcess...

private void LongDBProcess()
{
Session["IDCounter"] = i+1; //At this point, I am getting null
reference
}

If I am correct, the thread is not able to access the session. Probably this
thread's scope is outside the Application Domain whereas the session data
will be inside the Application Domain...am I correct?

Thanks for your pointers.

"OHM" wrote:

Quote:

Originally Posted by

This example ( albiet in Visual Basic.NET ) seems to work ok. Im not sure
what you are doing differently , or if I have misunderstood you ?
>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
>
Dim myThread As New Threading.Thread(AddressOf mySpawned)
>
Session("TestMe") = "Hello World"
>
myThread.Start()
>
End Sub
>
>
Private Sub mySpawned()
>
Dim s As String = Session("TestMe")
>
End Sub
>
>
>
>
>
"Diffident" <Diffident@.discussions.microsoft.comwrote in message
news:32A19AC0-DB0F-4120-8BF6-4E1539BEB0B7@.microsoft.com...

Quote:

Originally Posted by

Hi All,

I am trying to perform a non-CPU bound operation in an asynchronous
fashion
using 'Thread' and a delegate. Basically, I am spawning a thread using
ThreadStart and Thread.

My non-CPU bound operation needs to have access to Session variables; Even
though I embedded the state information (which also includes the context
object) in an object and passed the object to the Thread , I am unable to
access the Session variables. The system throws a Null Object Reference
error.

Since the thread that I am spawning is not from the CLR thread pool, it is
not able to access the Session variable. Am I right? How can a system
thread
get access to the Session variables of the current HTTPRequest?

I hope I articulated my problem. If not, please let me know.

Any pointers will be appreciated!


>
>
>


Hmm, not sure on this one. If you can do it with vb.net you should be able
to do it somehow with C#, but I cant get it to work either. The delegate is
obviously working ok, but it seems to have lost its connection to the
context.

I think its probably the way the thread has been started, but I dont
normally do that much with threading It's not something which rattles off
the tip of my head.

My suggestion is to repost this question on the C# newsgroup, someone there
is bound to have an answer pretty quick.

"Diffident" <Diffident@.discussions.microsoft.comwrote in message
news:92659A98-C334-4834-B95B-E74F14878594@.microsoft.com...

Quote:

Originally Posted by

Hi OHM,
>
Thanks for your response.
>
Here is what I am trying to do (in C#):
>
=====
>
ThreadStart t = new ThreadStart(LongDBProcess)
// LongDBProcess is a time-consuming process
Thread ts = new Thread(t);
t.start(); //At this point, system thread will be created and not
the CLR thread
>
====
>
I need to have access to Session variables inside my LongDBProcess...
>
private void LongDBProcess()
{
Session["IDCounter"] = i+1; //At this point, I am getting
null
reference
}
>
If I am correct, the thread is not able to access the session. Probably
this
thread's scope is outside the Application Domain whereas the session data
will be inside the Application Domain...am I correct?
>
Thanks for your pointers.
>
"OHM" wrote:
>

Quote:

Originally Posted by

>This example ( albiet in Visual Basic.NET ) seems to work ok. Im not sure
>what you are doing differently , or if I have misunderstood you ?
>>
>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Load
>>
> Dim myThread As New Threading.Thread(AddressOf mySpawned)
>>
> Session("TestMe") = "Hello World"
>>
> myThread.Start()
>>
> End Sub
>>
>>
> Private Sub mySpawned()
>>
> Dim s As String = Session("TestMe")
>>
> End Sub
>>
>>
>>
>>
>>
>"Diffident" <Diffident@.discussions.microsoft.comwrote in message
>news:32A19AC0-DB0F-4120-8BF6-4E1539BEB0B7@.microsoft.com...

Quote:

Originally Posted by

Hi All,
>
I am trying to perform a non-CPU bound operation in an asynchronous
fashion
using 'Thread' and a delegate. Basically, I am spawning a thread using
ThreadStart and Thread.
>
My non-CPU bound operation needs to have access to Session variables;
Even
though I embedded the state information (which also includes the
context
object) in an object and passed the object to the Thread , I am unable
to
access the Session variables. The system throws a Null Object Reference
error.
>
Since the thread that I am spawning is not from the CLR thread pool, it
is
not able to access the Session variable. Am I right? How can a system
thread
get access to the Session variables of the current HTTPRequest?
>
I hope I articulated my problem. If not, please let me know.
>
Any pointers will be appreciated!
>
>


>>
>>
>>


You want to use Asynchronous calls here, either with a Delegate, or using the
2.0 version, the Page class supports Asynchronous page methods and the
context can be passed.

Here is an example article that covers some of this:

http://www.eggheadcafe.com/articles/20060918.asp
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Diffident" wrote:

Quote:

Originally Posted by

Hi All,
>
I am trying to perform a non-CPU bound operation in an asynchronous fashion
using 'Thread' and a delegate. Basically, I am spawning a thread using
ThreadStart and Thread.
>
My non-CPU bound operation needs to have access to Session variables; Even
though I embedded the state information (which also includes the context
object) in an object and passed the object to the Thread , I am unable to
access the Session variables. The system throws a Null Object Reference error.
>
Since the thread that I am spawning is not from the CLR thread pool, it is
not able to access the Session variable. Am I right? How can a system thread
get access to the Session variables of the current HTTPRequest?
>
I hope I articulated my problem. If not, please let me know.
>
Any pointers will be appreciated!
>
>

Thread class and Session variable

Hi All,
I am trying to perform a non-CPU bound operation in an asynchronous fashion
using 'Thread' and a delegate. Basically, I am spawning a thread using
ThreadStart and Thread.
My non-CPU bound operation needs to have access to Session variables; Even
though I embedded the state information (which also includes the context
object) in an object and passed the object to the Thread , I am unable to
access the Session variables. The system throws a Null Object Reference erro
r.
Since the thread that I am spawning is not from the CLR thread pool, it is
not able to access the Session variable. Am I right? How can a system thread
get access to the Session variables of the current HTTPRequest?
I hope I articulated my problem. If not, please let me know.
Any pointers will be appreciated!This example ( albiet in Visual Basic.NET ) seems to work ok. Im not sure
what you are doing differently , or if I have misunderstood you ?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim myThread As New Threading.Thread(AddressOf mySpawned)
Session("TestMe") = "Hello World"
myThread.Start()
End Sub
Private Sub mySpawned()
Dim s As String = Session("TestMe")
End Sub
"Diffident" <Diffident@.discussions.microsoft.com> wrote in message
news:32A19AC0-DB0F-4120-8BF6-4E1539BEB0B7@.microsoft.com...
> Hi All,
> I am trying to perform a non-CPU bound operation in an asynchronous
> fashion
> using 'Thread' and a delegate. Basically, I am spawning a thread using
> ThreadStart and Thread.
> My non-CPU bound operation needs to have access to Session variables; Even
> though I embedded the state information (which also includes the context
> object) in an object and passed the object to the Thread , I am unable to
> access the Session variables. The system throws a Null Object Reference
> error.
> Since the thread that I am spawning is not from the CLR thread pool, it is
> not able to access the Session variable. Am I right? How can a system
> thread
> get access to the Session variables of the current HTTPRequest?
> I hope I articulated my problem. If not, please let me know.
> Any pointers will be appreciated!
>
Hi OHM,
Thanks for your response.
Here is what I am trying to do (in C#):
=====
ThreadStart t = new ThreadStart(LongDBProcess)
// LongDBProcess is a time-consuming process
Thread ts = new Thread(t);
t.start(); //At this point, system thread will be created and not
the CLR thread
====
I need to have access to Session variables inside my LongDBProcess...
private void LongDBProcess()
{
Session["IDCounter"] = i+1; //At this point, I am getting null
reference
}
If I am correct, the thread is not able to access the session. Probably this
thread's scope is outside the Application Domain whereas the session data
will be inside the Application Domain...am I correct?
Thanks for your pointers.
"OHM" wrote:

> This example ( albiet in Visual Basic.NET ) seems to work ok. Im not sure
> what you are doing differently , or if I have misunderstood you ?
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> Dim myThread As New Threading.Thread(AddressOf mySpawned)
> Session("TestMe") = "Hello World"
> myThread.Start()
> End Sub
>
> Private Sub mySpawned()
> Dim s As String = Session("TestMe")
> End Sub
>
>
> "Diffident" <Diffident@.discussions.microsoft.com> wrote in message
> news:32A19AC0-DB0F-4120-8BF6-4E1539BEB0B7@.microsoft.com...
>
>
Hmm, not sure on this one. If you can do it with vb.net you should be able
to do it somehow with C#, but I cant get it to work either. The delegate is
obviously working ok, but it seems to have lost its connection to the
context.
I think its probably the way the thread has been started, but I dont
normally do that much with threading It's not something which rattles off
the tip of my head.
My suggestion is to repost this question on the C# newsgroup, someone there
is bound to have an answer pretty quick.
"Diffident" <Diffident@.discussions.microsoft.com> wrote in message
news:92659A98-C334-4834-B95B-E74F14878594@.microsoft.com...
> Hi OHM,
> Thanks for your response.
> Here is what I am trying to do (in C#):
> =====
> ThreadStart t = new ThreadStart(LongDBProcess)
> // LongDBProcess is a time-consuming process
> Thread ts = new Thread(t);
> t.start(); //At this point, system thread will be created and not
> the CLR thread
> ====
> I need to have access to Session variables inside my LongDBProcess...
> private void LongDBProcess()
> {
> Session["IDCounter"] = i+1; //At this point, I am getting
> null
> reference
> }
> If I am correct, the thread is not able to access the session. Probably
> this
> thread's scope is outside the Application Domain whereas the session data
> will be inside the Application Domain...am I correct?
> Thanks for your pointers.
> "OHM" wrote:
>
You want to use Asynchronous calls here, either with a Delegate, or using th
e
2.0 version, the Page class supports Asynchronous page methods and the
context can be passed.
Here is an example article that covers some of this:
http://www.eggheadcafe.com/articles/20060918.asp
Peter
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Diffident" wrote:

> Hi All,
> I am trying to perform a non-CPU bound operation in an asynchronous fashio
n
> using 'Thread' and a delegate. Basically, I am spawning a thread using
> ThreadStart and Thread.
> My non-CPU bound operation needs to have access to Session variables; Even
> though I embedded the state information (which also includes the context
> object) in an object and passed the object to the Thread , I am unable to
> access the Session variables. The system throws a Null Object Reference er
ror.
> Since the thread that I am spawning is not from the CLR thread pool, it is
> not able to access the Session variable. Am I right? How can a system thre
ad
> get access to the Session variables of the current HTTPRequest?
> I hope I articulated my problem. If not, please let me know.
> Any pointers will be appreciated!
>