System.Web.SessionState.SessionStateServerHandler.SetAndReleaseItemExclusive C# (CSharp) Method

SetAndReleaseItemExclusive() public method

public SetAndReleaseItemExclusive ( HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem ) : void
context HttpContext
id string
item SessionStateStoreData
lockId object
newItem bool
return void
		public override void SetAndReleaseItemExclusive (HttpContext context,
								 string id,
								 SessionStateStoreData item,
								 object lockId,
								 bool newItem)
		{
			EnsureGoodId (id, true);
			byte[] collection_data = null;
			byte[] sobjs_data = null;
			MemoryStream stream = null;
			BinaryWriter writer = null;
			Stream output = null;
#if NET_4_0
			GZipStream gzip = null;
#endif
			
			try {
				SessionStateItemCollection items = item.Items as SessionStateItemCollection;
				if (items != null && items.Count > 0) {
					stream = new MemoryStream ();
#if NET_4_0
					if (config.CompressionEnabled)
						output = gzip = new GZipStream (stream, CompressionMode.Compress, true);
					else
#endif
						output = stream;
					writer = new BinaryWriter (output);
					items.Serialize (writer);
#if NET_4_0
					if (gzip != null)
						gzip.Close ();
#endif
					writer.Close ();
					collection_data = stream.ToArray ();
				}
				HttpStaticObjectsCollection sobjs = item.StaticObjects;
				if (sobjs != null && sobjs.Count > 0)
					sobjs_data = sobjs.ToByteArray ();
			} catch (Exception ex) {
				throw new HttpException ("Failed to store session data.", ex);
			} finally {

#if NET_4_0
				if (writer != null)
					writer.Dispose ();
				if (gzip != null)
					gzip.Dispose ();
#else
				if (writer != null)
					((IDisposable)writer).Dispose ();
#endif
				if (stream != null)
					stream.Dispose ();
			}
			
			stateServer.SetAndReleaseItemExclusive (id, collection_data, sobjs_data, lockId, item.Timeout, newItem);
		}