Parametarized Method Thread?
Mar 11, 2010i'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 Repliesi'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 RepliesI 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 RepliesI 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]....
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?
I want to introduce a slight wait during some testing functions, to simulate a server call. Is it sane to use Thread.Sleep(int) to introduce the wait or is there a better method to have the server wait?
Note, I'll be pausing long enough for me to visually see a sufficient lag, even tho I don't expect to see such a delay in the actual app. This is for me to visualize the actual delay that could occur.
I plan on running this both in the VS2010 local debugger webserver and in IIS 7. I'm on .NET 3.5
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?
How can we debbug a multi-thread program to see local variables of each thread using visual studio 2008.
View 1 RepliesI'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].....
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.
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.
I am creating an Asp.net web site which will support dynamic data. When I am creating a dynamic web site from Scratch (from template in VS) all is working fine. But when I am trying to add dynamic entity (.edmx) file and running the application I am getting following error
"The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'. "
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?
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 !
after invoking an async method using ThreadPool.QueueUserWorkItem how do i lookup the assigned thread id?
View 4 RepliesSo 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.
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 Repliessome 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
Does a PageAsyncTask fire off its own thread when used in a .aspx page?
View 1 RepliesI 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.
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?
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 RepliesI'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.
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
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?
[code]...
test in VS 2010 Professional and ASP.NET development Server no error.but in Server 2003 and IIS 6 show error:Server Error in '/' Application.Thread was being aborted.Description:An unhandled exception occurred during the execution of the current web request.Please review the stack trace for more information about the error and where it originated in the code.Exception Details:System.Threading.ThreadAbortException:Thread was being aborted.
Source Error:An unhandled exception was generated during the execution of the current web request.Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:[ThreadAbortException:Thread was being aborted.]
System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously) +486
[code]...