473,748 Members | 8,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Synclock in Begin request must be bad right?

I have had code in my Application_Sta rt which is intended to run once at
the start of my application's life.

It loads connection information and similar from a known location.

However I recently migrated my app using
-------------------------------------------------------------
%systemroot%\sy stem32\inetsrv\ APPCMD.EXE migrate config "Default Web Site/YourApp"
-------------------------------------------------------------

At which point my app's startup code was denied access to the request object.

I found a workaround which was to place the following code in the beginrequest

-------------------------------------------------------------
Private Shared InitializeLock As New Object
Private Shared InitializedAlre ady As Boolean
Sub Application_Beg inRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
SyncLock InitializeLock
If Not InitializedAlre ady Then

' My Initialise code goes here.

InitializedAlre ady = True
End If
End SyncLock
End Sub
-------------------------------------------------------------

This does work but I'm worried about performance
Jun 27 '08 #1
5 1831

Damn "Send" hotkeys. Sorry about that. I sent the previous message before
I was done writing it.
This does work but I'm worried about performance
Specifically it occurs to be that I now have a bottleneck in my application
which only one request can pass through at any one time.

This does not seem good for a web site.

Please tell me there is a better way.
Thanks in advance for any help.

--
Rory
Jun 27 '08 #2
Ok move on nothing to see here.

Just some shmuck accessing...

-------------------------------------------------------------
HttpContext.Cur rent.Request.Ap plicationPath
-------------------------------------------------------------

....from Application_sta rt when...

-------------------------------------------------------------
HttpRuntime.App DomainAppVirtua lPath
-------------------------------------------------------------
....would have worked just as well

Jun 27 '08 #3
Hi Rory,

From your previous messages, you currently encounter the following two
problems, correct?

1.the code in your ASP.NET's Application_Sta rt event which access a
certain object fails(with Access denied) after you switch to a new IIS
directory.

2. You can not get "HttpContext.Cu rrent.Request.A pplicationPath" property
work in Application_Sta rt event

As for the 1st problem, I wonder what is the exact object you're trying to
access, is it an COM object or something else, would you provide some code
snippet or further description? Such "Access denied" error is commonly
caused by security permission issues, therefore, is that certain object
access permission sensitive? If so, have you used "impersonat e" in your
ASP.NET web application. If you have used impersonate, the security account
under which the ASP.NET code executes are different between
Application_Sta rt and the "Begin_Request" (or any other page level event).
This is because Application_Sta rt executes at application level(there may
not exists any request context), it runs under ASP.NET worker process
account. Why "Begin_Requ est" is under the certain ASP.NET client request's
context, if you have used imperonate, it is running under the impersonate
account.
for the 2nd problem, it is actuall the same with the 1st one,
"HttpContext.Cu rrent.Request.A pplicationPath" this is a property coupled
with the current request's "HttpContex t". For each client request to
ASP.NET application, the runtime will attach an HttpContext object with the
request(during the server-side processing lifecycle). However,
Applicaiton_sta rt event is not a Request based event, it is just a global
application level event, there is no HttpContext associated with it,
therefore, if you try accessing any Httpcontext coupled property in it,
that will not be available.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>Date: Tue, 10 Jun 2008 11:30:57 +0000 (UTC)
Message-ID: <20************ **************@ news.microsoft. com>
From: Rory Becker <ro********@new sgroup.nospam>
Subject: Re: Synclock in Begin request must be bad right?
>

Damn "Send" hotkeys. Sorry about that. I sent the previous message before
I was done writing it.
>This does work but I'm worried about performance

Specifically it occurs to be that I now have a bottleneck in my
application
>which only one request can pass through at any one time.

This does not seem good for a web site.

Please tell me there is a better way.
Thanks in advance for any help.

--
Rory
>
Jun 27 '08 #4
Hello Steven Cheng [MSFT],
Hi Rory,

From your previous messages, you currently encounter the following two
problems, correct?

1.the code in your ASP.NET's Application_Sta rt event which access a
certain object fails(with Access denied) after you switch to a new IIS
directory.
My appologies if I gave the wrong impression here I am in fact able to access
the file in question, however I was having difficulty locating it as I needed
to locate the applications root directory and base it's location on that.
given that problem 2 is now solved, problem 1 ceases to exist.
>
2. You can not get "HttpContext.Cu rrent.Request.A pplicationPath"
property work in Application_Sta rt event
This was indeed the case.

for the 2nd problem, it is actuall the same with the 1st one,
"HttpContext.Cu rrent.Request.A pplicationPath" this is a property
coupled with the current request's "HttpContex t". For each client
request to ASP.NET application, the runtime will attach an HttpContext
object with the request(during the server-side processing lifecycle).
However, Applicaiton_sta rt event is not a Request based event, it is
just a global application level event, there is no HttpContext
associated with it, therefore, if you try accessing any Httpcontext
coupled property in it, that will not be available.
However it did used to fire at a point in time when there was an httprequest
available. It is only since the migration that this event has shifted.

This however has led to my discovery of 'HttpRuntime.Ap pDomainAppVirtu alPath'
which needs no such request to determine the information needed.
Thanks for your help anyway though

--
Rory
Jun 27 '08 #5
Thanks for your quick reply Rory,

I'm glad that you've found the solution. Yes, For ASP.NET web application,
in Application level event, it is better to avoid using those object which
is specific to HttpContext/Request. And the AppDomain properties you found
is not specific to any request context, but keep available based on the
given ASP.NET application(a certain .net AppDomain).

If you have any further questions, also welcome to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no
rights.--------------------
>Date: Wed, 11 Jun 2008 07:23:52 +0000 (UTC)
Message-ID: <3a************ **************@ news.microsoft. com>
From: Rory Becker <ro********@new sgroup.nospam>
Subject: Re: Synclock in Begin request must be bad right?
>Hello Steven Cheng [MSFT],
>Hi Rory,

From your previous messages, you currently encounter the following two
problems, correct?

1.the code in your ASP.NET's Application_Sta rt event which access a
certain object fails(with Access denied) after you switch to a new IIS
directory.

My appologies if I gave the wrong impression here I am in fact able to
access
>the file in question, however I was having difficulty locating it as I
needed
>to locate the applications root directory and base it's location on that.
given that problem 2 is now solved, problem 1 ceases to exist.
>>
2. You can not get "HttpContext.Cu rrent.Request.A pplicationPath"
property work in Application_Sta rt event

This was indeed the case.

>for the 2nd problem, it is actuall the same with the 1st one,
"HttpContext.C urrent.Request. ApplicationPath " this is a property
coupled with the current request's "HttpContex t". For each client
request to ASP.NET application, the runtime will attach an HttpContext
object with the request(during the server-side processing lifecycle).
However, Applicaiton_sta rt event is not a Request based event, it is
just a global application level event, there is no HttpContext
associated with it, therefore, if you try accessing any Httpcontext
coupled property in it, that will not be available.

However it did used to fire at a point in time when there was an
httprequest
>available. It is only since the migration that this event has shifted.

This however has led to my discovery of
'HttpRuntime.Ap pDomainAppVirtu alPath'
>which needs no such request to determine the information needed.
Thanks for your help anyway though

--
Rory
>
Jun 27 '08 #6

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

Similar topics

12
3054
by: Keith Langer | last post by:
I have some questions about whether synclock is necessary in a few different scenarios: 1) I have a Queue class which is shared between two threads. Thread 1 pushes objects onto the queue and Thread 2 pops objects off the queue one at a time (with no enumerators - just first in, first out). Does the Queue class need to be synclocked when objects are pushed on or popped off? 2) I have a boolean variable which can be read or written...
4
3789
by: fred | last post by:
If I have multiple threads running a Sub as below then a number of threads can be held up at the SyncLock. When it becomes free which thread goes first. Is it just by chance which thread goes first or do the threads queue in a FIFO or perhaps a LIFO bases. Thanks Fred Sub SomeWork()
10
3158
by: Bob Day | last post by:
Using vs 2003, vb.net sql msde.. Consider the following code snippets. See **** for questions. All are shared and accessed by multiple threads simultaneiously. ' Instantiate per for this shared class Private Shared gcCDsd As New Class_Component_Designer
3
2133
by: Bob Day | last post by:
Ok, I have done a lot of reading(of the newsgroup answers, help files and MSDN articles) of synclock. I understand what you are saying in the newsgroup, and it is very helpful. It does, however, directly contradict what the VS 2003 help file says, and it seems that various posters to my original questions on Synclock disagree with each other. It seems, that the best practice is to use sysnlock to protect code, not variables. That...
0
280
by: Johan Karlsson | last post by:
Hi all! I just need a true or false answer for this statement. Consider having a piece of code that boils down to this Dim a = new ArrayList SyncLock a SyncLock a a.Add("Something") End SyncLock
4
1971
by: Jeff Stewart | last post by:
Specifically, I don't understand the parameter that Synclock accepts. How is a reference type a lockable entity? What -is- a reference type? Is it a number? Is it a value at a specific memory location? Does synclocking a reference type put an entry in a catalog somewhere in the system, and it's removed on the "end synclock" statement? Are there any guidelines for creating synclock objects? I've found a surprisingly small amount of...
7
1625
by: SD | last post by:
I have a public object that I only want one thread to access at a time. However the access to this object is not limited to one procedure. Will SyncLock work in this case? If not what options do I have? Thanks SD Code in Module public A as Collection
1
565
by: fred | last post by:
I have a VB application that is using MS Access as its database. To avoid connection delays the application creates one connection to the database at start-up and maintains that single connection throughout until the application closes. I now want to use multithreading to improve the feel of the application but I need some help understanding Synclock. The aim here is to prevent any two threads from trying to use the same connection at the...
2
10054
by: HONOREDANCESTOR | last post by:
I have a buffer that needs to be locked sometimes, because 2 processes update it. So I made the buffer into a class and whenever there is code that affects it, I sandwich the code between Synclock MyBufferClass ........... End Synclock My question is, what is Synlock protecting? Is it just protecting
0
8830
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
9541
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
9370
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
9321
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
9247
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
8242
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
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
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

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.