473,383 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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(AddressOf ProcessFile)
NewThread.Priority = ThreadPriority.Lowest
NewThread.Start()
Response.Redirect("loading.aspx")

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.SerializationExceptio n
I have fixed the exception by adding the following line to the
Page_Load event:

Response.Cache.SetCacheability(HttpCacheability.No Cache)

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

Thanks,
Jeremy

Jan 19 '06 #1
2 1297
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.googlegr oups.com...
Hi all,

Here is the issue:

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

Dim NewThread As New Thread(AddressOf ProcessFile)
NewThread.Priority = ThreadPriority.Lowest
NewThread.Start()
Response.Redirect("loading.aspx")

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.SerializationExceptio n
I have fixed the exception by adding the following line to the
Page_Load event:

Response.Cache.SetCacheability(HttpCacheability.No Cache)

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
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...
1
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...
8
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...
31
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...
2
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...
5
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...
1
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. ...
8
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.