Lock Ever Get Stuck Locked Due To An Unexpected Thread Death Or Similar
Aug 11, 2010
I have an ASP.NET site that I am maintaining. Currently it has code that on first access (and other times too) goes and does a bunch of data caching by writing it to files. Currently it has no locking so we cna get problems with multiple people accessing the site and multiple threads trying to write to the files at the same time. This is obviously bad so I am going to implement some locking.
My current modified code just puts a simple lock around a section of code so that later requests just wait until the first request is done.
My concern is that I haven't used locks much so I just want to check if there is any situation in which that lock could not get released? For example I have no idea what happens if that first thread is killed (eg the web server decides its run too long and shuts it down). Does the lock get automatically freed at that point? Is there anything else I need to think about while doing this?
Edit to add:Here is what I think are relevant bits of Code in case there is anything I am doing stupid...
I am using private lock objects accessed through a dictionary and don't do anything much more than wrap some code in a SyncLock statement (equivalent of C# lock).
Public Shared Sub CheckAllVariables(ByVal SourceName As String, ByVal cn As HttpContext)
...
Do While dr.Read
projectID = dr.GetInt32(dr.GetOrdinal("ProjectID"))
Dim cacheLockObject As Object = GetCacheLockObject(projectID)code]....
Should I wrap access to the GetCacheLockObject function in a lock to prevent the possibility of two threads going in simultaneously and both finding the cache lock doesn't exist and then both creating it and returning different ones? I'm a little unused to having to consider thread safeness (assumign I am using that term correctly).
lock (this) { if (!isGoodPassword) Thread.Sleep(2000); } I would expect that this would allow all correct passwords without stalling, but if one user enters a bad password another successful password from a different user would also be blocked. However, the lock doesn't seem to lock across ASP.NET threads.
I'm developing an ASP.NET forms webapplication using C#. I have a method which creates a new Order for a customer. It looks similar to this; private string CreateOrder(string userName) { // Fetch current order Order order = FetchOrder(userName);[code]....
The problem here is, it is possible that 1 customer in two requests (threads) could cause this method to be called twice while another thread is also inside this method. This can cause two orders to be created.
How can I properly lock this method, so it can only be executed by one thread at a time per customer?
In an ASP.NET application, I have a resource that is protected by a ReaderWriterLockSlim.
Normal requests call EnterReadLock, access the resource, call ExitReadLock and return.
At one moment, I accidently forgot to put a call to ExitReadLock somewhere in my code. On the next request, I got an exception stating that the thread had already entered the lock.
Fair enough: if at the end of request A the thread does not exit the lock, and that same thread is used to process request B, and tries to enter the lock, it will throw.
Now, my question: is the following scenario possible? reasons?
thread begins to process request A thread enters lock thread does, say, sleep, or do some IO, and so becomes available same thread begins to process request B, while request A is "on hold" thread enters lock !! throws !!
If yes, what other solution do I have to protect said resource? Bearing in mind I want to use a ReaderWriterLockSlim because I also have other thread that may write to the resource?
edit: add some details: 1) This happens in the ProcessRequest method of an HttpHandler which generates, caches and serves images. These images are expensive to generate. So, the first request will generate and cache the image, and we want to put the other requests on hold while generating.
2) We have not tried to "reproduce" -- at the moment we're trying to know if it is possible or not that the same thread begins processing a request while already waiting for the image to become ready.
3) I am aware of the LockPolicyRecursion but I am not sure I fully understand its purpose, and whether it would be OK to set it to SupportsRecursion in our case.
edit: going further...According to the document pointed to by Ryan below, a thread will block and not return to the pool as long as we don't engage into async operations. So once we've locked the thread waiting for EnterReadLock to complete, it won't return to the pool nor process any other request.
So 1) we should be safe but 2) we might starve the thread pool. Assuming we don't want to immediately return a dummy "please wait" image, what solutions do we have?
I want to remove checked items from checklistbox (winform control) in class file method which i am calling asynchronously using deletegate. but it showing me this error message:-
Cross-thread operation not valid: Control 'checkedListBox1' accessed from a thread other than the thread it was created on.
i have tried invoke required but again got the same error. Sample code is below:
I have a remoting-type set up within my application where I avoid TargetInvocationExceptions and grab the inner exception. I invoke the internal PrepForRemoting method on the Exception class to preserve the stack trace from the invoked method.
This appears to construct the stack trace property correctly:
[code]....
Calling Server.GetLastError(); on Application_Error in Global.asax shows the correct stack trace. Where is the yellow screen stack trace coming from?
I'm new to threading and have used it successfully, but limited. I can spawn a thread and have the main thread reference variables in the spawned thread, but I don't know how to allow the spawned thread to reference (and update) variables in the main thread.
Any example threading code I've seen on the web appears to be WAY more complicated than what I do, so I am unable to understand or integrate into my code.
I want a example of multithreading .i want to use it in a web form not on console.i am using C#.net .and how to use thread.sleep method for a particular thread.
Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'. The request failed with the error message:
-- <html> <head> <title>Configuration Error</title> <style> body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } pre {font-family:"Lucida Console";font-size: .9em} .marker {font-weight: bold; color: black;text-decoration: none;} .version {color: gray;} .error {margin-bottom: 10px;} .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; } </style> </head> <body bgcolor="white"> <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1> <h2> <i>Configuration Error</i> </h2></span> <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "> <b> Description: </b>An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. <br><br> <b> Parser Error Message: </b>
It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.<br><br>
<b>Source Error:</b> <br><br> <table width=100% bgcolor="#ffffcc"> <tr> <td> <code><pre> Line 24: ASP.NET to identify an incoming user. Line 25: --> <font color=red>Line 26: <authentication mode="Windows"/> </font>Line 27: <!-- Line 28: The <customErrors> section enables configuration </pre></code> </td> </tr> </table> <br> <b> Source File: </b> c:inetpubwwwrootenterpriseweb.config<b> Line: </b> 26 <br><br> <hr width=100% size=1 color=silver> <b>Version Information:</b> Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082 </font> </body> </html> <!--
[ConfigurationErrorsException]: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
(c:inetpubwwwrootenterpriseweb.configline 26) at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Web.Configuration.RuntimeConfig.GetSectionObject(String sectionName) at System.Web.Configuration.RuntimeConfig.GetSection(String sectionName, Type type, ResultsIndex index) at System.Web.Configuration.RuntimeConfig.get_CustomErrors() at System.Web.Configuration.CustomErrorsSection.GetSettings(HttpContext context, Boolean canThrow) at System.Web.HttpResponse.ReportRuntimeError(Exception e, Boolean canThrow, Boolean localExecute) at System.Web.HttpRuntime.FinishRequest(HttpWorkerRequest wr, HttpContext context, Exception e) --> --.
Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'. The request failed with the error message:
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
<br><br> <b> Parser Error Message: </b>It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.<br><br> <b>Source Error:</b> <br><br> <table width=100% bgcolor="#ffffcc"> <tr> <td> <code><pre> Line 24: ASP.NET to identify an incoming user. Line 25: --> <font color=red>Line 26: <authentication mode="Windows"/> </font>Line 27: <!-- Line 28: The <customErrors> section enables configuration </pre></code> </td> </tr> </table> <br> <b> Source File: </b> c:inetpubwwwrootenterpriseweb.config<b> Line: </b> 26 <br><br> <hr width=100% size=1 color=silver> <b>Version Information:</b> Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082 </font> </body> </html> <!--
[ConfigurationErrorsException]: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
(c:inetpubwwwrootenterpriseweb.config line 26) at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Web.Configuration.RuntimeConfig.GetSectionObject(String sectionName) at System.Web.Configuration.RuntimeConfig.GetSection(String sectionName, Type type, ResultsIndex index) at System.Web.Configuration.RuntimeConfig.get_CustomErrors() at System.Web.Configuration.CustomErrorsSection.GetSettings(HttpContext context, Boolean canThrow) at System.Web.HttpResponse.ReportRuntimeError(Exception e, Boolean canThrow, Boolean localExecute) at System.Web.HttpRuntime.FinishRequest(HttpWorkerRequest wr, HttpContext context, Exception e) --> --.
I have a WCF Web Service that my ASP.NET app uses. It has been working fine for quite some time. I just added in a Dev Express Grid (and the Dev Express DLLs) and a new page that uses them and now I am getting parsing errors on the WSDL. But the weird part is that it works fine on my machine but fails on the web server machine. (Both are connecting to the same web services WSDL.) Here is the error message I am getting:
Server Error in '/MyWebAppWebDev' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Reference.svcmap: Failed to generate code for the service reference 'MyWebAppService'.
Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Referenced type 'WebClientApp.MyWebAppService.ReferenceUpdatesDataContract, WebClientApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' with data contract name 'ReferenceUpdatesDataContract' in namespace '[URL] cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types. XPath to Error Source: //wsdl:definitions[@targetNamespace='[URL]wsdl:portType[@name='IMyWebAppReferenceDataServiceLib'] Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on. XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='[URL]/']/wsdl:portType[@name='IMyWebAppReferenceDataServiceLib'] XPath to Error Source: //wsdl:definitions[@targetNamespace='[URL]/']/wsdl:binding[@name='MyWebAppServicesDefaultEndpoint'] Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on. XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='[URL]wsdl:binding[@name='MyWebAppServicesDefaultEndpoint'] XPath to Error Source: //wsdl:definitions[@targetNamespace='[URL]wsdl:service[@name='MyWebAppReferenceDataServiceLib']/wsdl:port[@name='MyWebAppServicesDefaultEndpoint']
I am completely stumped on this. I have checked my web.config endpoint address and it is spot on (and notably is not in the error message above).
Things I have tried:
Giving permissions to C:Windows emp to my Website user name Giving permissions to C:Windows emp to my App pool user name Checking to see that none of my data contracts are generic and have IsReference=true in them.
I am currently trying to display multiple items on a single page. I am not sure as to how to tackle this. What I have is a database table that has all the page data in. I have this run as a PagesController and this works fine. However what I would like to do is, if say the Products page is selected via the menu, I want to pull back not only the Products page html but also get all the products, and even be able to pull them through via category. I was trying to use a partial view, but I can't get it to work. The same would be for other pages, having partial views to display the other content, ie if Gallery is selected, the page html for Gallery shows and it then can push to a partial view that pulls all the gallery images from the gallery db table and so on.
Maybe I am tackling this the wrong way. I have the pages stored in the db to allow for a CMS system I have setup. Maybe I need to use models for all the other items(Products, Gallery, Videos and such) and use the partial for the page html?
fixed on my own. couldn't figure out how to pull stuff in from multiple tables into one view.
i have an application wherein i am accessing the Session object in the CommonCode.cs file that resides in the App_Code folder. But when the session object is accessed the application throws me an error Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the \ section in the application configuration.Now i have already enabled the session state property in the web.config file, here is my code from the web.config file:
I set up a DAL layer in a dll. This had a couple poorly named methods such as GetData(), which is the default name offered up in the tableAdapter wizard. I also added a few other methods for various reasons, all with better names. I then built the dll and referenced it in an ASP project. On one page, I added an ObjectDataSource, and set it to that tableAdapter (which isn't what I wanted to do, but that's a different story). Under the Select tab, I see the GetData and the other methods. Under the Update tab I see a variety of Update methods. Under the Insert and Delete tabs....I see the same methods as I saw under the Update tab. The Insert and Delete methods that exist for the tableAdapter were not available.
I figured that I did something wrong, and I didn't like that GetData name, so I went back to the dll and changed some things around (I think I added an Insert and Delete method, but by now I can't remember, except to say that I wasn't all that surprised not to see those two methods the first time). I also changed the GetData name to something else, then rebuilt the dll.
Since that time, I have yet to be able to change what shows up in the Object Data Source configuration. The Select adamantly insists on the GetData method, which no longer exists under that name, while the other three tabs all show a variety of Update methods, but neither Insert nor Delete. I noticed that just adding a reference didn't have any impact until the ASP project was built, which moved the dll to the bin folder where it needs to be for the Object Data Source configuration wizard to see it. Therefore, I deleted the dll from the bin folder, then rebuilt. I've also removed the reference, deleted the dll from the bin folder, rebuilt, added the reference, rebuilt again to get the dll back into the bin folder, and anything else I can think of. It still seems to be retaining the original schema from the tableadapter without ever updating to the new name for the GetData. Since that hasn't updated, the rest doesn't surprise me.
I have CheckedListbox and grid. Based on what are the items checked in listbox that much of items need to be shown in grid. My SQL procedure like ; select * from Emp where city in (@Names)
Everything is ok if I am checked any of the item and click OK. If I am nothing checked from the listbox I need to display all of the cities from DB. I need to do this work without modifying my procedure. So need to work out in front/end. If I pass nothing from the code the query seemed as select * from Emp where city in ('') So no records getting...
I'm all set up with Visual Developer 2010 Express and successfully (yaaah) worked my way through the NerdDinner tutorial (thank you, thank you, thank you!). So, I think I have everything set up correctly so far. I used the "Install Everything" without the prebuilt apps and all went smoothly.
However, my goal is to set up CMS for a small company owned by a relative so they can update their website as necessary. I'd love to do this with MVC.
I have tried to install both N2 CMS and Umbraco, but can't get past the admin and user names and passwords for the database. Since I'm failing with both apps, I think it's something about setting up the database server that I need to understand.Win 7 Home Premium 64, home system, not on a network. what I need to enter for admin / admin passwords and user / user passworks for N2 CMS and Umbraco?
I've written a desktop application using VB.NET and SQLEXPRESS. Now I am trying to deploy it to WS 2k3. But getting positive results wiht SQLE is proving difficult. Here is the connection string I am using:
The problem is the results I get from the setting of 'User Instance'. Like it is, it loads a unique stance of SQLE, which is fine. But the instance just keeps eating memory. I tried limiting memory with sp_configure, but nothing happened. It just keeps growing. If I exclude 'User Instance', it uses the SQLE service running on my machine. It ignores the memory limitation, but eventually settles and stops growing.
Those results came from working on my local machine.When I put it on 2k3, I get the same results with User Instance = True; runaway memory. With User Instance = False, I start getting the 'attempt to attach an auto-named database failed' message. So now I am stuck. I would like to go with the 'User Instance = true' option, but I don't know how to deal with the runaway memory. If all else fails, I could use the =False option, but I just can't get 2k3 to allow.
I've built a ASP.NET webservice and I'm trying to access it from a Blackberry. I've been testing it out with multiple devices and the simulator and it works fine, but there's just the one Blackberry 9000 (It's not the model, I've tried it out with another Blackberry 9000), and it's stuck waiting for a response from the server. Relevant section of the code that accesses this -
System.out.println("IN ntwk access thread, start point"); HttpConnection connection = (HttpConnection)Connector.open(serviceURL + WSNAME); connection.setRequestMethod(HttpConnection.POST); connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Content-length", Integer.toString(postData1.length)); OutputStream requestOutput = connection.openOutputStream(); requestOutput.write(postData1); requestOutput.close(); final int responseCode = connection.getResponseCode(); if(responseCode!= HttpConnection.HTTP_OK) { //Process the error condition } // Request succeeded process the data.
It seems to be getting stuck after connection.getResponseCode(). Is there some way I can verify what's going wrong with this particular device?
I want to give iD in textbox1 and submit after submitting it Text Box 2 should get ID and Barcode both so that from there I can get print ... how can i do this process..
public void CreateBarcode(string data) { imgPath = string.Format("{0}{1}.png", path, data); Bitmap barcode = new Bitmap(1, 1); Font threeOfNine = new Font("IDAutomationHC39M", 60, System.Drawing.FontStyle.Regular,
I have a form that allows users to post text to a MySQL database using an OdbcConnection. Everything works great until a user entered unicode characters into the textbox and sends the data. Suddenly the page freezes and is not redirected to the next page as programmed. When I check the database later it comes up with all of the users data intact, including the unicode characters. I've duplicated this problem several times by entering unicode characters and then entering only ASCII. It happens every time unicode characters are used. Is the problem on the ASP.Net side or the MySQL side? Here is my code. The description string is from a textbox entered on the form.I thought about using a RegEx to get rid of any non-ascii characters before sending the data. Is that recommended? How do I do it?
My ASP.NET application will have to handle HTTP GET requests that will have the following URL format: [URL] currently the requirement is to validate that there're no parameters in the query string except id and indicate an error like "unknown parameter P passed". Is such requirement a good idea? Will it interfere with some obviously valid cases of using the application I haven't thought of?
when my xml file is big, I get the following error unexpected end of file while parsing name has occurred. Line 1, position 2034 the xmlData debug showed that not all the xml file is being read
[Code]....
I read that the memory of the string variable is not big enough to handle the xml file, what can I use to be able to read big xml files. my program works for small xml text.
I am transfering data from DB server to second DB server using one test page.
But i am getting following unexpected message ....
The CLR has been unable to transition from COM context 0x205480 to COM context 0x2055f0 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.