473,790 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session serialization error when threading

Hi all,

Here is the issue:

On postback, I spawn a new thread using the following code:

Dim NewThread As New Thread(AddressO f ProcessFile)
NewThread.Prior ity = ThreadPriority. Lowest
NewThread.Start ()
Response.Redire ct("loading.asp x")

ProcessFile() is a method in the code-behind class of the currently
executing page. After the thread spawns, any time I access the Session
object I get the following exception:

System.Runtime. Serialization.S erializationExc eption
I have fixed the exception by adding the following line to the
Page_Load event:

Response.Cache. SetCacheability (HttpCacheabili ty.NoCache)

This seems totally strange to me, does anyone know why this fixed the
error?

Thanks,
Jeremy

Jan 19 '06 #1
2 1315
you can not safely access the session from a background thread. asp.net
serializes page requests to the same session object to prevent numerous
contention issues. if you use inproc sessions (never a good idea with
production machines), you could pass a reference to an object stored in the
session to the background thread, but you will have to add code to make it
threadsafe

-- bruce (sqlwork.com)


"Jeremy Cowles" <je***********@ gmail.com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
Hi all,

Here is the issue:

On postback, I spawn a new thread using the following code:

Dim NewThread As New Thread(AddressO f ProcessFile)
NewThread.Prior ity = ThreadPriority. Lowest
NewThread.Start ()
Response.Redire ct("loading.asp x")

ProcessFile() is a method in the code-behind class of the currently
executing page. After the thread spawns, any time I access the Session
object I get the following exception:

System.Runtime. Serialization.S erializationExc eption
I have fixed the exception by adding the following line to the
Page_Load event:

Response.Cache. SetCacheability (HttpCacheabili ty.NoCache)

This seems totally strange to me, does anyone know why this fixed the
error?

Thanks,
Jeremy

Jan 19 '06 #2
Thanks for the reply, but that doesn't really answer my question...
you can not safely access the session from a background thread.


In my post, I said it's working fine now. I am not having any problems
with reading/writing sessions values. The problem I am having is
understanding why turning off page cache had anything to do with the
exception being thrown. Any thoughts on that?

Jan 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6333
by: PJ | last post by:
I posted a few days ago concerning requests being blocked from a main window after a popup window had initiated a file download. Apparently this has to do with the fact that asp.net or iis serialize all requests from the same session. Further requests from the same session are being queued until the download is complete. So, is there any way to override this? Is there anyway to tell asp.net to not serialize same session requests? Is...
1
3722
by: Bill L | last post by:
Hi guys, Because of restarting application after new DLLs installed into \Bin folder , we move the session to StateServer, everything'a alright except when I try to write any simple hash table into session. The Error message shows like ---------------------------------------------------------------------------- ----- Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not...
8
1509
by: MattB | last post by:
Hello I am starting a new thread in a button click event. This thread calls an method which sends emails, I don't want the page to wait for the emails to finish going out as it slows the user down. I have to set a session to null in the same click method but when I do this I get this funny error.
31
7011
by: Harry Simpson | last post by:
I've come from the old ASP camp where session variables were not used. When i started using ASP.NET in 2001, I started using them again because it was ok from what I'd read. I've been merrily using Session variables for three years now and i'm entering a project with my new boss who has never quite come around that session variables are ok. What's the concensus here. How can i convince him that they are ok in ASP.NET. OR
2
5047
by: jakk | last post by:
Below is the exception that Iam getting. It says that the DataView that Iam storing in the session is not Serializable. BUt works fine if I store in the inproc session and fails if I switch to storing the session in Sql Server. Please let me know if Iam doing anything wrong. Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when
5
5694
by: sdettmers | last post by:
Hi, Database: SQL Server Session: SQL Server Language: C# Application: ASP.Net I have created a login page which attempts to retrieve the users record from the database and I store the validated users DataRow into Session which is in SQLServer. I have listed the error below for you to
1
1468
by: js | last post by:
Does anybody knows how to solve the problem? I added attribute to the following classes in Microsoft.Practices.EnterpriseLibrary.Data namespace, but I still get the error. Thanks. Database.cs DatabaseFactory.cs DatabaseProviderFactory.cs DBCommandWrapper.cs
8
9459
by: rgparkins | last post by:
Hi I am creating a sign-up process on a web site much like that of a wizard form. I have browsed many sites to look for examples of how to store the entry data, so that the user can go back and forward along the sign -up process. I am currently trying to use a Session object to store all these details and get them back out of session as each step is selected. My model was a HashTable of NameValueCollection, so I could go to the hash...
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10413
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9986
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.