C# - Locking An Application Variable?

Dec 10, 2010

I'm using a 3rd party web service in my ASP.NET application. Calls to the 3rd party web service have to be synchronized, but ASP.NET is obviously multi-threaded and multiple page requests could be made that result in simultaneous calls to the 3rd party web service. Calls to the web service are encapsulated in a custom object. My thought is to store the object in an application variable and use the C# lock keyword to force synchronized use of it.

I'm nervous, because I'm new to multi threaded concepts and I've read that you shouldn't lock a public object (which my application variable effectively is). I've also read that if the locked block of code fails (which it could if the web service fails), then it could destabilize the app domain and bring down the application.I should mention that the 3rd party web service is rarely used in my website and it's going to be rare that 2 requests to it are made at the same time.Here's a rough code sample of how I'd make calls to the web service:

ThirdPartWebService objWebService = Application["ThirdPartWebService"] As ThirdPartWebService;
lock (objWebService)
{
objWebService.CallThatNeedsToBeSynchronized();
}

View 4 Replies


Similar Messages:

DataSource Controls :: SSIS: RetainSameConnection And Variable Locking?

Jun 8, 2010

I am modifying a rather large ETL package using BIDS. It builds a datawarehouse, so there are many sources and a single destination. There are quite a few data flow tasks, and their connection strings are read into variables from an encrypted source. All the data flow tasks are arranged serially because of variable locking issues - occasionally two DFTs attempt to simultaneously lock the variable and it fails. I realize there are script solutions out there, but I am looking for perhaps a more elegant (easier) solution than to apply scripted solutions to tons of packages over something so trivial.

I came across the "RetainSameConnection" connection property, and I have a hunch this could be the solution. My reasoning is: If there's only one connection to a data source, there should only be one read operation from the variable. At least, it makes sense when SOURCING.As for destinations, I'm not sure if it's a good idea to have data from multiple sources flowing in through a single connection.This is my first week working in ETL so I don't know all the nuances of databases, ETLs, connections, etc.

View 1 Replies

Does Record Locking (Pessimistic And Optimistic Locking) Is Applicable

Oct 8, 2010

Does record locking (Pessimistic and Optimistic Locking) is applicable in ASP.NET application? If so, What is the pros and cons on doing this?

View 3 Replies

Locking Down Application To Everyone?

Nov 5, 2010

I use the app_offline.htm file to bring my site down when I have to roll a new revision. However, even after I launch I'd like to be able to play around and test my site before anyone else has access. Since almost all of my pages are available without logging in, I need to way to lock down my application to everyone but myself and obviously the app_offline.htm file won't for for this.

I have a BasePage class and I'm thinking the only way to do this would be to put code in that class's Page_Init method and I could check for my specific IP address and kick everyone whose IP doesn't match to the app_offline.htm file. However, I'm wondering if this would be the best method since my IP will change.

View 3 Replies

Application Variable Versus Web.Config Variable

Aug 24, 2010

Which is better from a performance perspective?

Accessing a Global Application Variable (Application["foo"])

versus

Accessing an AppSetting variable from the web.config

Does .NET Cache the AppSetting variables so that it is not accessing the web.config file with every use?

View 2 Replies

State Management :: Use Session Variable From Application To Another Application?

Apr 27, 2010

I Want To Use A Session Variable From One Application to Another Application. Is That Possible in ASP.NET 3.5 Or Greater To Use Session Variables As i Required. My Both Applications Host In Same IIS Server.

Me To Sort Out This Prob. ASAP

View 1 Replies

C# - Application Variable Refresh In An Mvc Web App?

Feb 4, 2010

I have an Application level variable that gets loaded from a database when the application starts. Now when accessing the variable, I check to see if it is not null. If it is not null I use it, if it is null I initialize it from the database, then use it.

My question is how can I make sure that this variable is refreshed atleast once a day? Is there something in .net or the MVC framework to help with this?

Does IIS unload an application if it has not accessed for a while? If so then my variable would be refreshed each time the app is reloaded.

View 1 Replies

Application Variable Instead Of Session?

Dec 28, 2010

i am redirecting from a 3rd party site to my application where i am getting the responses of credit card no,cvv no and exp date into my application.but the session data that had come from the previous page is being lost.i have tried using application instead of session and its working fine will there be any disadvantage of using application over session

View 9 Replies

How Much Data Can Be Stored In Application Variable

Mar 9, 2010

How much data can we store in Application variable in ASP.net.

View 1 Replies

How To Store An Application Variable By Javascript

Feb 10, 2010

how could i store a Asp.net Application variable by javascript.

View 2 Replies

WCF / ASMX :: Set Webserver As Application Variable?

Jan 24, 2011

I'm trying to set my WebService to a Application variable, but I can't use after all...

Application["sorts"] = new Sorts.Sorts();

Ok, so when I type Application["sorts"] and put a periond in front, instead get the list of the WebService methods I just get the Equals, GetHashCode,

GetType and Tostring.Probably it's belongs to the Application thing itself.

View 1 Replies

Share Application Variable Between 2 Websites (IIS 7.5)?

Oct 31, 2010

I have two urls that are supposed to lead to the same actual folder.

I can't do a redirect because the websites are built so they question the URL and perform accordingly.

So I built two application in the IIS (I tried using a virtual directory for one of them, but I kept crashing on the web.config can not be read). Everything works perfectly except the Application variables which are different between the two addresses. (Specificly I'm counting the number of current users logged on).

View 2 Replies

ADO.NET :: EF - Record Locking?

Mar 8, 2011

I'm about to begin a new web project using asp.net 4.0 (EF 2.0). I have a question on row locking...customer is concerned that if employee 1 has a record in edit mode, they want to lock the row and make it uneditable for other users, until employee 1 has saved their changes. A step further is, if employee #2 attempts to edit the locked record, a notification would appear, notifying employee #2 that "Employee #1 John Doe" has the record locked and to contact them.

View 4 Replies

How To Change Application Variable Value On Closing Browser

Jun 11, 2010

I want to Change application variable value on closing browser, Problem is; I am using sessionState mode="StateServer" and in this mode, Session_end event does not fire in global.asax

how i can detect session_end or browser close and then change the application variable?

View 1 Replies

Configuration :: Passing Variable Externally To VB.NET Web Application?

Nov 18, 2010

I need to make the connection string in my vb.net web application be passed into the app externally. This is so I can re-driect the app to use either a test or production database. The same idea as a .INI file in a windows base system. someone suggested to me I use XML but I dont know how to do that.

View 13 Replies

Static Variable Inside A Class In Web Application

Jul 28, 2011

I understand the problem of the static variable inside a class in the web application, now I try to create a simple class to deal with SQL Server for example, so I created Static Method inside this class, this static method used in insert, update and delete from database, I wonder if this is safe, and there is no problems will appear ?

View 10 Replies

Web Forms :: Locking Id Into Databse?

Sep 14, 2010

i have create a form..and i generate ID using dropdown list for user for registration before they save the page..the ID will appear when click "signUp" button.("ID" not saved yet into database)

i want the "ID" lock into databse when click "signUp" button..

View 3 Replies

Iis7 - IIS Is Locking PInvoke Dll?

Nov 11, 2010

I have an ASP.NET MVC website that uses an internal dll for some PInvoke stuff. The dll is located in the /bin folder next to the other assemblies. This works well, but if I want to replace the content of the /bin folder with the newest set of files by copying onto the existing files (this is on a test server) the PInvoke dll is locked/used by the w3wp.exe worker process and cannot be replaced except after you recycle the apppool or restart IIS.

Is this standard behavior or can I somehow instruct the ASP.NET runtime to take a shadow copy of the PInvoke dll similar to the regular assemblies?

View 1 Replies

MVC :: Save Chat Room Data In Application Variable Or DB, Where Is Better?

Nov 4, 2010

My application is MVC Web App Chat Room , it supports following features:1.Create/Join/Close room 2.Send message in room (just live message, offline message might be supported in future)I have done logic for application, but I'm considering where to save chat room data (message,room information, and users in room) ? I see there are 2 options:1. Application variable2. Using file or database-What if I saved in Application variable:In case of there are 2000 rooms and 10000 users online, mean I have to persistence in Application variable (actually in RAM memory) information of 2000 rooms, more than 10000 message (text), these numbers might be increased by second if there are more users online in real time. and what's next ? I don't know what will happen to server, crash ? or my web app will be terminated ? whatever I don't want both results !

-What if I saved in file or DB (i.e: SQL Server DB) Because of web application, clients have to send request every 1 second to fetch data (messages and user list in room). So in case of there are 2000 rooms and 10000 users online, means they will make 10000 requests every 1 second to DB. I don't know what will happen to DB, there are a lot of connections and in EVERY 1 second, can DB still be alive to serve request ?I don't know where saving is good now because both seem are bad solution

View 2 Replies

Save Chat Room Data In Application Variable Or DB?

Nov 4, 2010

My application is Web App Chat Room , it supports following features:

1.Create/Join/Close room

2.Send message in room (just live message, offline message might be supported in future)

I have done logic for application, but I'm considering where to save chat room data (message,room information, and users in room) ? I see there are 2 options:

1. Application variable

2. Using file or database

-What if I saved in Application variable: In case of there are 2000 rooms and 10000 users online, mean I have to persistence in Application variable (actually in RAM memory) information of 2000 rooms, more than 10000 message (text), these numbers might be increased by second if there are more users online in real time. and what's next ? I don't know what will happen to server, crash ? or my web app will be terminated ? whatever I don't want both results!

-What if I saved in file or DB (i.e: SQL Server DB) Because of web application, clients have to send request every 1 second to fetch data (messages and user list in room). So in case of there are 2000 rooms and 10000 users online, means they will make 10000 requests every 1 second to DB. I don't know what will happen to DB, there are a lot of connections and in EVERY 1 second, can DB still be alive to serve request ?

I don't know where saving is good now because both seem are bad solution :(. What is your opinion ?

View 1 Replies

DataSource Controls :: Locking The Database?

Jan 12, 2010

I have multiple database running in my SQL Sever , in that I need to lock only one database is there is any inbuilt method in SQL Server 2008

View 1 Replies

Databases :: Locking Down The Proc Table?

Feb 27, 2010

I'm working on locking down some MySQL user accounts. At the moment I typically grant my user accounts execute privileges over the required stored procedures within a schema.Now I'm looking at the proc table in the mysql schema. The common wisdom that's quoted many times on various websites says "Stored procedures require the presence of the proc table in the mysql schema".By granting select access over the proc table stored procedures will work. But if I removed the above select privilege and grant the user execute privilege over the entire mysql schema the procedure will also work.

Does anyone have any ideas about the security issues by choosing one of the above over another?I would prefer to lock the proc table down all together so the user cannot see it cannot select from it.

View 1 Replies

.NET Web App Deadlocking - It's Caused By SQL Server Locking

Mar 6, 2010

Our client's web app restarts suddenly at random intervals. For each restart, we've found an entry like this in the Windows Event Log:

Event Type: Warning
Event Source: W3SVC-WP
Event Category: None
Event ID: 2262
Date: 2/21/2010
Time: 1:33:52 PM
[code]...

View 2 Replies

Active Directory Account Locking Out On First Try?

Jul 6, 2010

I have a website which requires users to enter their corporate network username and password. It then looks for that account in Active Directory and gets a list of any email addresses associated with that account.

The problem I am having is that ONE incorrect password is locking out an account. Our domain policy is that an account will lock out after three incorrect entries, so I am assuming that I am doing something wrong in my code. I am not very knowledgeable about Active Directory or .NET DirectoryServices in general, which may be apparent from my code. Here it is:

public ArrayList AuthenticateActiveDirectory(string Domain, string UserName, string Password)
{
// An error occurs if the username/password combo does not exist.
// That is how we know it is not a valid entry.
try

[Code].....

View 1 Replies

VS 2013 / PDF Protecting / Stamping And Locking?

Jun 9, 2015

I have an ASPNET Application (C#) that runs on my company intranet. This application allows the users to attach PDF files against records.

I am trying to get that PDF uploaded in such a way that whenever the user initially uploads (the uploaded PDF will always be unlocked PDF), the user name would be stamped on the PDF file and the files is locked by my application so that the user cannot change the PDF again, even when having a PDF Writer. Whenever required the application should allow the user to unlock the PDF and then allow the user to edit the PDF.

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved