I have a program that continually polls the database for change in value of some field. It runs in the background and currently uses a while(true) and a sleep() method to set the interval. I am wondering if this is a good practice? And, what could be a more efficient way to implement this? The program is meant to run at all times.
Conse...
Or is it okay to do something like this:
new Thread( new ThreadStart( delegate { DoSomething(); } ) ).Start();
?
I seem to recall that under such a scenario, the Thread object would be garbage collected, but the underlying OS thread would continue to run until the end of the delegate passed into it. I'm basically looking for ThreadPo...
I am thinking on the following approach but not sure if its the best way out:
step1 (server side): A TaskMangaer class creates a new thread and start a task.
step2 (server side): Store taskManager object reference into the cache for future reference.
step3 (client side): Use periodic Ajax call to check the status of the task.
Basical...
I have a dialog in MFC with a CStatusBar. In a separate thread, I want to change the pane text of status bar. However MFC complains with asserts? How is it done? An example code would be great.
...
I have a method which should be delayed running for a specified amount of time.
Should I use
Thread thread = new Thread(() => {
Thread.Sleep(millisecond);
action();
});
thread.IsBackground = true;
thread.Start();
Or
Timer timer = new Timer(o => action(), null, millisecond, -1);
I had read some articles about using Thread.S...
Our application allows the user to change the Culture that they run it under and that culture can be different than the underlying OS Culture. The only way that I have found of doing this is by setting Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture for every thread.
The only problem with this is that we mu...
Will the following code result in a deadlock using C# on .NET?
class MyClass
{
private object lockObj = new object();
public void Foo()
{
lock(lockObj){
Bar();
}
}
public void Bar()
{
lock(lockObj){
// Do something
}
}
}
...
I have a servlet S which handles callbacks from a 3rd party site.
The callback invocations happen in a specific order. Thus, I need to queue them.
I propose to use an in-memory queue like
java.util.ConcurrentLinkedQueue
So the logic looks like this:
Servlet S receives a callback & queues the received item into queue Q.
By this ...
A web crawler script that spawns at most 500 threads and each thread basically requests for certain data served from the remote server, which each server's reply is different in content and size from others.
i'm setting stack_size as 756K's for threads
threading.stack_size(756*1024)
which enables me to have the sufficient number of t...
I came across this article discussing why the double-check locking paradigm is broken in java. Is the paradigm valid for .net (in particular, C#), if variables are declared volatile?
...
I have a class which is not thread safe:
class Foo {
/* Abstract base class, code which is not thread safe */
};
Moreover, if you have foo1 and foo2 objects, you cannot call foo1->someFunc() until foo2->anotherFunc() has returned (this can happen with two threads). This is the situation and it can't be changed (a Foo subclass is...
I was reading the following article:
http://msdn.microsoft.com/en-us/magazine/cc817398.aspx
"Solving 11 Likely Problems In Your Multithreaded Code" by Joe Duffy
And it raised me a question:
"We need to lock a .NET Int32 when reading it in a multithreaded code?"
I understand that if it was an Int64 in a 32-bit SO it could tear, as it is...
Okay, I have this program and I don't want more than one instance of it running. So what I have right now is it grabs all instances that match it's name, and if there are more than one it quits and lets the user know it's already running in another instance.
However, there is a special case in which the new instance will want change wha...
General tutorial or good resource on how to use threads in Python?
When to use threads, how they are effective, and some general background on threads [specific to Python]?
...
I have some questions about multi-threaded programming and multi-core usage.
In particular I'm wondering how the operating system and/or framework (this is .NET) deals with cores that are heavily used.
Here's my questions regarding threads:
When a new thread is spawned, what is the algorithm for assigning the thread to a particular c...
Is the .NET class System.Net.CookieContainer thread safe? --Update: Turnkey answered--
Is there any way to ensure thread safeness to variables which are modified during asynchronous requests (ie. HttpWebRequest.CookieContainer)?
Is there any attribute to highlight thread safe classes? --Update: If thread-safeness is described on MSDN th...
I have a reference-type variable that is readonly, because the reference never change, only its properties. When I tried to add the volatile modifier to it the compiled warned me that it wouldn't let both modifiers apply to the same variable. But I think I need it to be volatile because I don't want to have caching problems when reading ...
How to do garbage collection in a program that consist from multiple threads or processes?
I also like to know how can I scan the stack from each of those threads and processes?
Does each process require it's own garbage collection routine? Is it a good idea to run the garbage collector in a separate thread/process from the actual prog...
I can't seem to find a .NET answer to this problem, which I would have thought would be fairly common.
What is the best pattern for unit testing an asynchronous method?
Obviously I need to call the method and then see if the callback fires, but is there a better way than simply sleeping for a bit and then checking for a flag that is set...
Short of inserting a try/catch block in each worker thread method, is there a way to deal with unhandled, non-ui thread, exceptions in Windows Forms?
Thread.GetDomain().UnhandledException works great for catching the error, but by then it's too late to do anything about it (besides log it). After control passes out of your UnhandledExce...