Thread Safety Around "web" CurrentSessionContext / ISessionFactory.GetCurrentSession?
Jan 31, 2011
I've seen some code that puts a lock around the following code:
if (!CurrentSessionContext.HasBind(sessionFactory))
{
CurrentSessionContext.Bind(sessionFactory.OpenSession());
}
ISession session = sessionFactory.GetCurrentSession();
[code]...
sessionFactory is a DI-injected singleton and the configuration uses a "web" (not "managed_web") context.
Am I correct in assuming that this code does not require synchronised access?
View 1 Replies
Similar Messages:
Dec 17, 2010
The question is, is it possible that requests for the same session are executed from multiple threads? Are methods in ASP.NET reentrant? Especially we are using AJAX which means that asychronous requests are taking place.
Would this mean to place locks around operations on objects placed inside the session?I know that locks are essential when handling static and application wide variables, but the question is is the same true for session objects?
View 2 Replies
Jan 10, 2011
Assuming a static method like below is called from ASP.NET page,can a different thread(b) overwrite the value of s1 after the first line is executed by thread(a)?If so, can assigning parameters to local variables before manipulation solve this?
public static string TestMethod(string s1, string s2, string s3)
{
s1 = s2 + s3;
....
...
return s1;
}
Is there are a simple way to recreate such thread safety related issues?
View 3 Replies
Dec 5, 2010
On the MSDN page for the Membership.ApplicationName property (which applies to an asp.net membership provider), it warns that although one can change Membership.ApplicationName in code, 'The ApplicationName property is not thread safe for multiple writes, and changing the ApplicationName property value can result in unexpected behavior for multiple users of an application.' They therefore recommend avoiding using it for a 'web application'.
This is because the default SqlMembershipProvider is written as a singleton. But here's my question: is it OK if all the threads in my application process are going to set Membership.ApplicationName to the same thing?
I'm thinking of having multiple applications on my IIS box, each with their own separate application pool. I want to point them to the same location, but based on the hostname, set the application provider to different things. Wouldn't this actually be OK? It might not be a thread-safe operation, but doesn't each application pool have its own process and therefore its own instance of SqlMembershipProvider? So, every thread that tried to set Membership.ApplicationName for a given SqlMembershipProvider instance would be trying to set it to the same thing (the provider that is appropriate for that hostname).
View 1 Replies
Apr 2, 2010
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:
[code]....
View 1 Replies
Jan 27, 2010
How can we debbug a multi-thread program to see local variables of each thread using visual studio 2008.
View 1 Replies
Nov 24, 2010
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.
Here is a quick example of how I use threading:
[code].....
View 3 Replies
Jul 15, 2010
I have a hidden input on my form, and my JavaScript code writes there dynamically generated string based on the user behavior on the page.Later, I access to that inpput via server side code.Many users will be using this page at the same time, so what about thread safety ?I mean, could it be possible that userA has an access to that string generated by userB ? Or maybe server will read that string from each user's Web Browser ?
View 2 Replies
Mar 24, 2010
I am reading the Asp.net security documentation on msdn.I come across these tow terms and get really confused.
# WindowsIdentity = WindowsIdentity.GetCurrent()
which returns the identity of the security context of the currently executing Win32 thread.
# Thread = Thread.CurrentPrincipal
which returns the principal of the currently executing .NET thread which rides on top of the Win32 thread.
View 1 Replies
Jun 25, 2010
I have a password page and when someone enters an incorrect password I want to simply foil a brute force attack by having
bool isGoodPassword = (password == expected_password);
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.
View 4 Replies
Aug 27, 2010
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.
View 5 Replies
Jan 2, 2011
I need an explanation regarding some advice I got on this site. I'm doing a newsletter sending app, and I have my mail sent in a seperate thread so the process doesn't slow down the whole web site. A couple of people advised me to set the threads IsBackground property to true. I did this, but was also courious about what this does, so I googled a bit.
As it turns out, setting the IsBackground property to true indicates that "it's okay if the process shuts down while this thread is still running.". Or as microsoft puts it "Any remaining background threads are stopped and do not complete." I don't know if I got this the wrong way but, wouldn't it be better to leave the IsBackground property to false, so that the spawned thread can complete its work regarding the main thread?
View 2 Replies
May 8, 2010
I want to execute a process, but after the process is done i would like to execute a query so i know this process is done.The process called ffmpeg is quite big so i start it and wait til its done with this coding:
ffmpeg.Start(); // start !
View 5 Replies
May 18, 2010
after invoking an async method using ThreadPool.QueueUserWorkItem how do i lookup the assigned thread id?
View 4 Replies
Apr 3, 2010
So basically here I am trying to wait for my server to connect to my website signaling it that its done and so the page needs to be refreshed(cause sql was updated). Thing is when I try to use the response/request in the thread it simply doesn't want to work.
Here the code
Code:
[code]....
Errors I am getting are:
1. If I have the headers clear thing there it gives requires integrated IIS pipes or something like that.
2.If I don't have the clear headers it says the headers were already sent.
View 13 Replies
Feb 24, 2011
Can we consider that two clients accessing the same method of a web service at the same time are two threads (with all problems involved...) ?Is it the same thing for methods in an asp.net web application ?
View 3 Replies
Mar 16, 2010
some details of image:
MessageID 14 and 19 are starting thread.
1 0 Yogendra1 Mishra 19 new msg
0 14 Yogendra1 Mishra 17 y
0 14 Yogendra1 Mishra 16 y
1 0 Yogendra1 Mishra 14 y
i want max messageid of each thread.
now my output should be.
19
17
View 5 Replies
Mar 16, 2010
Does a PageAsyncTask fire off its own thread when used in a .aspx page?
View 1 Replies
Jan 21, 2010
I am executing time consuming task in a new thread. ParameterizedThreadStart pts = new ParameterizedThreadStart(WorkingFoo); Thread thread = new Thread(pts);
The WorkingFoo executing the task and keeps track of the progress steps (it can return the total number of "steps" and the current step).
I want to display this information in a progress bar (simple div or ajax control, I don't mind).
I don't want, ofcourse, visually refresh the page that will display the progress. Also I want to reduce as much as possible the number of postbacks. So how do I do that? How to show the current progress from new thread on the web page? Also the page that shows the progress can be closed and re-opned and still get the current status.
View 1 Replies
Feb 23, 2011
I have a thread that runs querying a DB and returning some values. If this values satisfyes a condition, I want to raise a message box (javascript alert) for the client side.
In my system, users can post some tasks in DB, and the thread is going to constantly query the database to check if user has things to do. If user has, the system must alert him through a message box.
I've done javascripts invokings with ClientScript.RegisterStartupScript, and Attributes.Add for buttons. But now I want to call the javascript functions (wich will alert the user that he has things to do) from the midle of a sub (that is executed in a thread), without a submit, load or click event. How can I do it?
View 2 Replies
Mar 30, 2010
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?
I tried;
Mutex mutex = null;
private string CreateOrder(string userName) {
if (mutex == null) { [code]....
This works, but on some occasions it hangs on WaitOne and I don't know why. Is there an error, or should I use another method to lock?
View 5 Replies
Mar 11, 2010
i'm trying to call a method with 3 parameters in a thread but i couldn't figure that out ..since it only accepts a non parametarized methods.
View 7 Replies
Feb 24, 2010
I have a WCF service method that's running in a worker thread I spin from another method. I need to map a relative service app path ("~/Templates/a.template") to the physical path ("D:WebTemplatesa.template"), but I can't use HttpContext.Current.Server.MapPath because HttpContext.Current is null in a worker thread. How else can I reach MapPath method?
View 2 Replies
Apr 15, 2010
I'm trying to read a static property from a static class, which is being modified from a different thread.
Basically I have this static class:
public static class Progress{
public static int currentProgress{get; set;}
}
and this thread manipulating the currentProgress:
private void Job(){
for(int i = 0; i<100; i++){
Progress.currentProgress = i;
Thread.Sleep(1000);
}
}
While this is running, I have a HttpHandler trying to access this progress (every few seconds), like so:
public void ProcessRequest(HttpContext context) {
context.Response.Write(Progress.currentProgress.toString());
context.Response.End();
}
But the currentProgress is set to it's initialvalue here, while the workThread is working, and only when done, is the currentProgress updated.
View 1 Replies
Oct 27, 2010
I run a loop that downloads a lot of smal files from another website
try
Loopstarts
result = runData()
loop ends
catch ex1 as exception
End try
private function runData() as string
Dim wc as new WebClient
Dim str as string
try
str = wc.downloadstring(filePath)
catch ex2 as exception
return "Nothing"
end try
wc.dispose()
finally
return str
end function
THE Problem is if the file is not found in the RunData function I get 'Thread being aborted' error which stops the not only the function RunData() but also the loop is running in, so I get an error in ex2 as well as ex1. But I want the error to be captured in ex1 and stop, and not effect the loop.
I have read that you need to use Response.End to close the thread or not to capture the 'threadbeingaborted' expception.
BUT how do you do the response.end with a webclient??? (IN vb.net , asp.net 2.0 version
View 2 Replies