C# Execute 2 Threads Simultaneously?
Feb 27, 2011
I am trying to reproduce a threading error condition within an HTTP Handler.
Basically, the ASP.net worker procecss is creating 2 threads which invoke the HTTP handler in my application simultaneously when a certain page loads.
Inside the http handler, is a resource which is not thread safe. Hence, when the 2 threads try to access it simultaneously an exception occurs.
I could potentially, put a lock statement around the resource, however I want to make sure that it is infact the case. So I wanted to create the situation in a console application first.
But i cant get 2 threads to execute a method at the same time like asp.net wp does. So, my question is how can you can create 2 threads which can execute a method at the same time.
Edit:
The underlying resource is a sql database with a user table (has a name column only). Here is a sample code i tried.
[TestClass]
public class UnitTest1
{
[TestMethod]
public void Linq2SqlThreadSafetyTest()
[Code]....
View 1 Replies
Similar Messages:
Feb 15, 2011
I'm trying to understand how to execute AJAX animation on an asp button that has to execute code on Postback. In other words, I have button with code behind that needs to be excuted, but at the same time want to be able to have one of animation extenders be applied to it. I understand that I need to use the BeginRequest Event, I'm just not sure how, or which javascript commands to use to call the ajax animation so the postback will still occur.
View 5 Replies
Mar 10, 2011
I am looking through a sql stored procedure which I might need to update in the near future. Basically the stored procedure is about 20 lines long. The stored procedure first builds a query
and stores it in a variable named "@Sql". And then for the last two lines of the stored procedure it appears that the big sql statement stored in "@Sql" is executed by using the "EXEC" command. See below. What is confusing though is that the query appears to be exectuted twice? Why was the query written in this way. Don't both lines do the same thing? Why is it being done twice? Could this possibly be a mistake on the
part of the person who wrote the query. Below are the two lines I am talking about?
EXEC sp_executesql @sql
EXEC (@sql)
View 4 Replies
Jan 6, 2011
I built a little web application that displays charts. I was thinking that it might be useful for the superuser of the app to do a complete data refresh, however this process takes around 10 minutes to complete. I was thinking perhaps the user could click a button that would start off a new thread to do a data refresh and subsequent clicks would kill the thread and restart the data population process. The user would then be free to browse about the site and view the charts as their data is populated.
Is there a simple method of accomplishing something like this?
View 3 Replies
Aug 20, 2010
I'm trying to get a better handle on how threads work in ASP.NET, so I have a test site with a few pages, and I have a test WinForms client that creates 40 roughly concurrent requests to the test site. The requests take about 5-10 seconds to complete--they call a web service on another server. When I run the test client, I can use Fiddler to see that the requests are being made concurrently. However, when I look at Performance Monitor on the web server, with counters "ASP.NET Apps v2.0.xxx/Requests Executing", "ASP.NET/Requests Current", "ASP.NET Requests Queued", these counters never display more than 2.
This is the case regardless of whether the test page I'm requesting is set up with Async=True and using the Begin/End pattern of calling the web service, or if it's set up to make the call synchronously. Judging by what I see in Fiddler, I would think I should be seeing a total of 40 requests in one of those states, but I don't. Why is that? Do these counters not mean what I think they mean?
View 1 Replies
Nov 1, 2010
In the main thread I open a new thread that gets the number of new messages of user (takes about 5 secs) and this second thread should save the number in some place.
In the main thread I should check the "some place" and if the value exists I display it on the page.
Where can I save the value from the second thread to read it from the main one? This value is unique per user so I can't use static field.
View 3 Replies
Feb 21, 2011
I have a method that I call 8 times with different parametres.I use
AvailableYears.AsParallel()
.Select<Int32,DateUsedByThread>(x => GetDataForYearWorker(x,CIF))
.ToList();
GetDataForYearWorker gets the response from a webservice synchronously. It uses very little computing power on my asp.net application, but it ussualy takes 3-5 sec for each webservice response. Because the calls to the webservice are independent of eachother, I want to make tham all at the same time. But it looks like only 2 threads can run at the same time. Why is this and how can I have 8 threads working at the same time?
View 1 Replies
Mar 5, 2011
I'm using ASP.NET 4.0 on IIS7.5 and WCF Callback technique. I have no problem with callback. The wcf service can fire callback method in web client but it seems it's on another thread with the UI thread.
public partial class _Default : System.Web.UI.Page, IServiceCallback
{
private IService proxy = null;
private static TextBox _textBoxtest;
protected void Page_Load(object sender, EventArgs e)
[Code]....
how to update my textBox from callback event.
View 2 Replies
Apr 1, 2011
I have two ASP.NET AJAX UpdatePanels . there are two timers with diffrent intervals. is it possible to update two updatepanels simultaneously together ? like multi thread application . each should be UpdatePanel Update in separate thread in one time. i wrote this code but second timer does not work :
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to ASP.NET!
</h2>
<p>
[Code]....
View 1 Replies
Oct 5, 2010
I'm investigating some performance improvements that can be made to our web server and ASP.NET application.This page contains a few things that we can do.We currently have two worker processes running as a garden. Do each of these worker processes have their own ASP.NET threadpool? Or do both of these worker processes share a single threadpool and the max number of worker threads is shared across these processes?This post seems to suggest that the two processes share a common ASP.NET threadpool. All w3wp.exe threads do is take requests from HTTP.SYS queue, process it, and hand the request toASPNET_ISAPI.DLL, who then deposits those requests into the ASP.Net request queue, and the ASP.Net threadsBut this post suggests that each worker process contains their own ASP.NET threadpool. Each process (w3wp.exe) has its own CLR thread pool which has the configured maxworkerthreads value (20 default).
View 1 Replies
Feb 15, 2011
When my asp.net page loads,it needs to get data from 2 webservices.I want to make the data retrieval processes work concurently.How can I do this and update Label1 with the text result from WS1 and label2 with the result from WS2?I don't know how the code should look like in order to be able to update the controls on the page.
View 1 Replies
Mar 30, 2010
I need to run the HttpContext.Current.Server.Execute method in my ASP.NET application. This application has a WCF operation that does some processing. Currently, I am to do my processing correctly from within my WCF operation. However, I would like to do this asynchronously.
In an error to attempt this asynchronously, I tried running Server.Execute in the DoWork event handler of a BackgroundWorker. Unfortunately, this throws an error that says
"object reference not set to an instance of an object" The HttpContext element is not null. I checked that. It is some property nested in the HttpContext object that appears to be null. However, I have not been able to identify why this won't work. It happens as soon as I move the processing to the BackgroundWorker thread.
My question is, how can I asynchronously execute the Server.Execute method?
View 1 Replies
Feb 26, 2011
i am doin my final year project and in my project i want to watermark multiple images simultaneously where image,logo,position,alpha and key value is stored in a database table ....i need to retreive these details from db table and perform watermark on those images....
View 3 Replies
Apr 11, 2010
Do I have to lock access to instance members?
public class HttpModule : IHttpModule
{
//...
Dictionary<int, int> foo;
void UseFoo(int a, int b)
{
foo[a] = b;
}
}
View 2 Replies
Nov 28, 2010
[Code]....
How to get SUM in TextBox1 = Najdinaloge.Kilometrov.ToString();
and how to get SUM in TextBox2 = TextBox2.Text = Najdinaloge.Kilometrov2.ToString();
If I use
var Najdinaloge = (from p and db.tbl_PotniNalogis
join t and db.tbl_RelacijeZaMestneVoznjes
[code]....
works, but there is only one figure sum.
View 4 Replies
Jun 15, 2010
When I do ThreadPool.QueueUserWorkItem, I don't want unhandled exceptions to kill my entire process. So I do something like:
ThreadPool.QueueUserWorkItem(delegate() {
try { FunctionIActuallyWantToCall(); }
catch { HandleException(); }
});
Is this the recommended pattern? It seems like there should be a simpler way to do this. It's in an asp.net-mvc app, if that's relevant.
View 1 Replies
Mar 5, 2010
I am using HTTP load testing tool to stress test my asp.net 2.0 application. I faced problem that, when I have 1 user access to the system (currently only test on login.aspx), it is very fast ~ 1-2 secs. However, when I run with 10 virtual users at the same time, it takes 10-12 secs for each.
User Response Time (s)
1 10.12
2 10.22
3 11.00
...
10 12.78
My question is, why ALL of them also takes 10-12 secs? Is it normal? I was thinking that should be some users take 2-3 secs and some 5-6 secs and etc.
View 4 Replies
Jan 12, 2011
I have 2 Web applications in the same IIS with the virtual directory structure below:
http://www.mydomain.com/site1
http://www.mydomain.com/site2
both site1 an site2 are using form authentication and creating the token further adding in cookie as below,
FormsAuthentication.Initialize();
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,username,DateTime.Now, DateTime.Now.AddMinutes(20),rememberMeSet,globalID ,FormsAuthentication.FormsCookiePath);
// Encrypt the ticket.
String hash = FormsAuthentication.Encrypt(ticket);
//Create the authentication cookie
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
My problem is when I'm logging in to Both site1 and site2 then these two are not running simultaneously on single browser using different tab for same user name.one is being logged out when logging to the other application and vice verse.
View 3 Replies
Feb 17, 2011
I have Asp:TextBox,Asp:RegularExpressionValidator and Asp:RangeValidator on .aspx page.
These two validators have ControlToValidate value equal to textBox Id.
RegularExpressionValidator have validation Expression such that it allows only number.
Range validator have maximum value ="100" and if I enter any text then both validators get fired .
Logically only RegularExpressionValidator should fire if I enter any textvalue.
Is there any property of Range validator such that it check for numeric value to compare and disbled if value entered in textBox is some text so that no handling of event(Client side and Server side both) is required.
View 1 Replies
Mar 21, 2011
I have an update panel in my ASP.NET web form with a trigger that will fire a click event when the contents within my update panel is updated (it's a grid view with fields). The event that is fired when then take the changes user made and do some calculation and then update another update panel with that information. This is all fine and dandy when the user tabs along the form and fill out the form in a orderly fashion before hitting any buttons on the page.
If a user accidentally hits another button on the page while changing the content in my grid within the update panel, for example, the user enter a value in my grid view control, without tabbing, the user click the save button. Logically, i believe that the trigger should fire the click event first (event A), and then the save button event (event B). But, consistently I haven't seen event A gets fire correctly while event B gets fire all the time. is there a way to ensure event A always gets fired before event B? also if event A update another update panel without the page will event B fire after the update is complete?
View 1 Replies
Dec 20, 2010
I have a web application hosted in IIS 7.5 and expose its functionality using web services. The web application has state the the first thing I do is to call a web service method to start it all up. As a consequence several threads are created and these threads run until the system is stopped. All recycling of application pools and such is disabled! To access the web services the calling client must authenticate (using basic auth and local windows users). Thus, an incoming request has the CurrentPrincipal set. The logging subsystem is setup to tag all log messages with the current principals identity name and this works just fine for code that runs on an the thread of on incoming request. But, it doesn't work at all for all of my background threads. The current principal is still set in these threads but the identity objects name has been disposed. Why is this? What can I do to fix this. I would really like to get all log messages tagged with the current principal. It also seems impossible to detect if the identity name instance has been disposed without trying to access it and catch the exception which is highly annoying.
View 2 Replies
Oct 24, 2010
I have two ajax time for my aspx web page but while the one is ticking , the other stops running. How can i make it both timer run together like the windows form?
View 1 Replies
Jan 5, 2010
I had the following code to send different mails to differnt users in my asp.net web application
foreach (DataRow dataRow in dataTable.Rows)
{
sendMails();
[code]...
View 8 Replies
Mar 1, 2011
ASP.NET 2.0
We have an old app we are moving to a new server and the dates are screwing up (we are in England dd/MM/yyyy) on an assynchronous thread.
Googling it appears that each thread needs to be set to a specific culture otherwise it defaults to the 'OS default locale'. We don't want to change the code so looks like we need to change the os default locale.
Just to be completely clear - does a new thread in asp.net default to the app.config setting (no), machine.config settings (?), app pool account settings (Network Service in our case), Local Service or the Local System account locale settings? Can the default be changed through the Administration tab in regional setting (WS2008)?
Second question, when looking at Environment.UserName, it is showing the server name (xxxx$) rather than Network Service (which is running the app pool). Why is this?
Also, do we need to worry about Input Language, or just Format (locale)?
Is it possible for the Welcome Page to be showing as English (United Kingdom) but the system accounts to actually be English (United States)?
View 1 Replies
Sep 13, 2010
I've got a thread that sends emails around. I need to generate ActionLinks as part of the content of the email so the user can click on the link and be redirected to the website, exactly to the required page. I tried to instantiate a UrlHelper class and use it's Action method to generate the link but since threads don't run within the context of any request I get exceptions at the time of generating the ActionLink.
View 2 Replies