Thread ID From ThreadPool.QueueUserWorkItem?
May 18, 2010after invoking an async method using ThreadPool.QueueUserWorkItem how do i lookup the assigned thread id?
View 4 Repliesafter invoking an async method using ThreadPool.QueueUserWorkItem how do i lookup the assigned thread id?
View 4 RepliesThis may be due to a lack of understanding of what's going on under the hood or simply a lack of understanding of threading in general. When a user logins I need to run some tasks that call web services to update data in my system. Since the services could take a considerable amount of time I thread the entire process. However, even though I think I'm running the whole series of tasks in a thread separate from my application, my application waits until the called function is finished before it proceeds.
WindowsIdentity identity = WindowsIdentity.GetCurrent();
Manager manager = (Manager)Session["Manager"];
ThreadPool.QueueUserWorkItem(new SafeWaitCallback().Call(identity, delegate(object noCallBack)
{
manager.RunAccountUpdater(identity);
}));
The application hangs until the function "RunAccountUpdater" is finished and the callback occurs. What am I doing wrong/not understanding?
From a web page I start a time consuming job and update it's status on the UI using webmethod.
Job is done in a thread:
ThreadPool.QueueUserWorkItem(new WaitCallback(DoJob), parameters); Job set's it status using static properties, and when web page, using javascript, calls web method it read those properties.
[System.Web.Services.WebMethod]
public static ProcessStatus GetProgressStatus()
{
Jober.Lock.EnterReadLock();
ProcessStatus st = new ProcessStatus(Jober.PercentageCompleted, Jober.TotalNumber);
Jober.Lock.ExitReadLock();
return st;
}
The UI progress is updated through javascript, the problem is that after thread completes I need to update UI on server side, so javascript won't help me here. What Is the best way to signal when thread is completed?
I have a web service that uses ThreadPool to delegate a task to a thread but it runs on ASPNET (System.Environment.UserName) while the main thread runs as windows account. How can I make this thread run with same windows account. Note that I have impersonate=true in web.config. This is causing problems accessing database.
View 1 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 am trying to use ThreadPool.QueueUserWorkItem to send daily newsletter to my website subscribed members (about 500 members) at 2:00 am every day automatically.I placed record on txt file everytime send out email for debuging, then I found that only about 165 members been send out. every day is different number but just about.never finished whole 500 members.looks like thread aborted before finish sent out all emails.anybody knows what's going on here?I am using shared hosting, so I couldn't run my own window service for this.
View 1 RepliesHow 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 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 RepliesIn an async http handler, we add items to the ASP.NET cache, with dependencies on some files. If the async method executes on a thread from the ThreadPool, all is fine:
AsyncResult result = new AsyncResult(context, cb, extraData);
ThreadPool.QueueUserWorkItem(new WaitCallBack(DoProcessRequest), result);
But as soon as we try to execute on a thread out of the ThreadPool:
AsyncResult result = new AsyncResult(context, cb, extraData);
Runner runner = new Runner(result);
Thread thread = new Thread(new ThreadStart(runner.Run());
... where Runner.Run just invokes DoProcessRequest,
The dependencies do trigger right after the thread exits. I.e. the items are immediately removed from the cache, the reason being the dependencies.We want to use an out-of-pool thread because the processing might take a long time.
So obviously something's missing when we create the thread. We might need to propagate the call context, the http context...
Note: off-the-shelf custom threadpools probably solve this. Writing our own threadpool is probably a bad idea (think NIH syndrom). Yet I'd like to understand this in details, though.
This MSDN example for an Asynchronous Handler starts the new thread using ThreadPool.QueueUserWorkItem.
I thought that you should not use ThreadPool.QueueUserWorkItem to start the new thread as the thread is taken from the ASP.net thread pool and defeats the purpose of using an Asynchronous handler.
Is the example wrong?
My application is a asp.net 3.5 running on iis 6 (windows 2003)
This application is serving 1000's of users daily (100-500 users online).
I want to send an email newsletter to customers weekly.
Around 200,000 emails every time.
This is the code im using:
ThreadPool.QueueUserWorkItem(new WaitCallback(AsyncProcessMailerQueue), null);
private static void AsyncProcessMailerQueue(object data)[code]....
When testing this locally (on my dev machine) i see the application is working alot slower.
Is there a better way to write this code? Should i use ThreadPool.QueueUserWorkItem or create a new thread using Thread t = new Thread(new ThreadStart(DoWork)); ? Will it be better to create a totally seperate application for the purpose of sending the newsletters. will that help if ill run this application on the same machine?
i've seen other posts here talking about ThreadPool vs Thread but its seem no one is sure which is better.
Am implementing the threadpool concept and have doutbt in threads being created.
[Code]....
Initially i gave (1,1) in semaphores and only one thread was created and it did only one task, and (5,5) created one thread and it used for all the times.
Is ter anything wrong in wat i did or any other way of doin other than semaphores. And mainly wat abt the remaining 20 threads in threadpool? its a waste of CPU right. Can i create only 5?
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 !
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.
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'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'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