imagine I write a library in C. Further, imagine this library to be used from a multi-threaded environment. How do I make it thread-safe? More specific: How do I assure, that certain functions are executed only by one thread at a time?
In opposite to Java or C# for example, C has no means to deal with threads/locks/etc., nor does the C ...
I have a console application that sends customized emails (with attachments) to different recipients and I want to send them concurrently. I need to create separate SmtpClients to achieve this so I am using QueueUserWorkItem to create the emails and send them in separate threads.
Snippet
var events = new Dictionary<Guid, AutoResetEve...
I'm using a BackgroundWorker to perform a long computation (only one such computation at a time).
The user has the possibility of cancelling the worker (calling worker.CancelAsync).
In the worker.DoWork method I periodically check for the cancel pending flag and then return from the method.
Then the Completed event is raised from the ...
Okay, here's the deal...
I have a Windows (XP) program in .NET 2.0 (C#) which allows users to rename a given .pdf file. (The filename is "structurally descriptive", as it lays out simple info about what's in the file itself.) On the program's only form, there is a LinkLabel object which allows the user to open the .pdf itself, so that...
I am aware that System.Threading.Timer exists, but I already have a Thread. This thread is supposed to stay alive all the time, but only execute every X seconds. The test implementation looks like this:
public class MailClass
{
private Action<string> LoggerAction;
private bool _exit;
public MailClass(Action<string> loggerAc...
Hi,
I am trying to implement a queue thread that listen to some messages . What is the fastest way to do it , this is one-process mulitple thread application.
Should I use Apache Qpid ? or just a regular .NET Blocking Queue Class (as in http://www.eggheadcafe.com/articles/20060414.asp)?
I will be happy to hear your experience on this m...
Recently I tried to Access a textbox from a thread (other than the UI thread) and an exception was thrown, it said something about the "code not being thread safe" and so I ended up writing a delegate (sample from MSDN helped) and calling it instead.
But even so I did'nt quite understand why all the extra code is necessary
Update:
Will...
We're building an async thread per client server and stumbled upon a problem. We want the thread to always be ready to either read or write to\from the socket. We currently use the socket's reading method which is blocking and as a result we cannot issue any write requests.
is there a way to interrupt the read operation?
perhap...
I have generated dumps on four servers and am analyzing the output of !threadpool and !threads. I noticed the roughly consistent following output:
0:024> !threadpool
CPU utilization 0%
Worker Thread: Total: 2 Running: 0 Idle: 2 MaxLimit: 200 MinLimit: 2
Work Request in Queue: 0
Number of Timers: 27
Completion Port Thread:Total: 2 Free: ...
I have something like this:
for(int i=0; i<5; i++){
mytextarea.setText("hello " + i);
try{
Thread.currentThread().sleep(1000); //to give time for users to read
} catch(Exception e){}
}
I'm expecting it will display "hello 0" in the text area, wait for 1 second, then display "hello 1", then wait for 1 second, etc.
...
I have a bunch of procedures that need to be executed successively until either they are all executed, or a certain condition is met. Here's the basic code that needs to be executed until a condition is met:
public boolean search()
{
robot.go();
robot.spin();
//etc - around 8 more similar commands (each takes around 2 seco...
In a previous question I asked how to improve a bit of code. It was said that I should move it to a new thread. I'd never thought about it before so it seems like a great idea to me. So this morning I went ahead and reused a bit of code I already have for processing emails and updated the way I handle image uploads into my site.
So is t...
I have a multithreaded .Net C# application, it uses Direct3D 9/10 and XAudio2. (Direct3D is accessed by only one thread, same for XAudio2. Direct3D isn't the problem cause the error is manifest in either DX9 or DX10 mode without any change in its behaviour.)
Sometimes (there are some areas that gives this problem randomly) this applicat...
Exposition:
I think the Java VM is awesome. It's guarantee of the safety of bytecode, the the standard libraries, ... are amazing, especially the ability to load a Java class on the fly, and know that it can't crash the VM (good luck with *.so files or kernel modules).
One thing I don't understand, is how Java treats Thread.stop
I've ...
I use QueueUserWorkItem() function to invoke threadpool.
And I tried lots of work with it. (about 30000)
but by the task manager my application only make 4~5 thread after I push the start button.
I read the MSDN which said that the default number of thread limitation is about 500.
why just a few of threads are made in my application?
I'm...
I'm trying to write a unit test for my FileWatcher class.
FileWatcher derives from a Thread class and uses WaitForMultipleObjects to wait on two handles in its thread procedure:
The handle returned from FindFirstChangeNotification
A handle for an Event that lets me cancel the above wait.
So basically FileWatcher is waiting for whate...
I'm going to add a python console widget (into a C++ GUI) below some other controls:
Many classes are going to be exposed to the python code, including some access to GUI (maybe I'll consider PyQt).
Should I run the Python code in a separate thread?
I think it's a good approach, because GUI won't be frozen while executing long co...
Hi,
I've recently wrote a C# console time tabling algorithm that is based on a combination of a genetic algorithm with a few brute force routines thrown in. The initial results were promising but I figured I could improve the performance by splitting the brute force routines up to run in parallel on multi processor architectures. To d...
Hi everybody,
at the moment I am trying some of the new Features of the Task Parallel Library,
shipped with the .Net Framework 4.0 Beta 2.
My question relates specifically to the Exception Handling within the TPL as
described here:
http://msdn.microsoft.com/en-us/library/dd997415%28VS.100%29.aspx
First example (changed it a little bi...
I have a Private Sub Fill(), which im trying to call from button1, in the form of
Dim t1 As System.Threading.Thread = New System.Threading.Thread(AddressOf Me.Fill)
t1.Start()
However, when I run the program nothing happens. I click the button numerous times and the function isnt being executed. What gives? The Fill function is basi...