I was noticing that when I run a multi-threaded app from within the IDE and
then I close the main form (which spun off all of the threads), that the
Stop/Pause VCR buttons in the debugger are still available & working. It's
like closing the form did not actually cancel the threads.
From my earlier discussions on the newsgroup, I know how people already feel
about Thread.Abort(), so I was wondering what I need to do to "clean up"
when closing a main form that has spun off worker threads (I was under the
impression that this cleanup would automatically happen, but seeing the
Stop/Pause VCR buttons on the debugger being active & working tell me
otherwise).
Any thoughts would be appreciated.
--
Doug Thews
Director, Customer Solutions
D&D Consulting Services
----------------
Visit my Tech Blog at: http://www.ddconsult.com/blogs/illuminati/
Nov 16 '05
21 1654
Agreed. It's probably better to just use "true" instead of a variable, and
then catch the Interrupted exception (if you want a thread that runs
continuously and only quits when the app quits - as I was suggesting):
try
{
while( true )
{
// perform whatever
}
}
catch (ThreadInterrup tedException)
{
// Perform cleanup - then return
return;
}
--
Doug Thews
Director, Customer Solutions
D&D Consulting Services
----------------
Visit my Tech Blog at: http://www.ddconsult.com/blogs/illuminati/
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** @msnews.microso ft.com... Santi <__***********@ ibcentre.es> wrote: A thread ends when it exists the function that it is executing. If the thread performs a continuos loop you usually use a boolean to control the execution, something like:
bool run;
void Foo() { while( run ) { // perform whatever } }
So what I do to stop and end the thread in a clean way is:
run = false;
this makes the executuion flow to exit the function and end the thread.
Note that as written, this isn't thread-safe. Either run should be made volatile, or you should put a lock round both the reading and writing of it.
See http://www.pobox.com/~skeet/csharp/t...latility.shtml
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Doug Thews <do*******@remo veme.ddconsult. com> wrote: Agreed. It's probably better to just use "true" instead of a variable, and then catch the Interrupted exception (if you want a thread that runs continuously and only quits when the app quits - as I was suggesting):
try { while( true ) { // perform whatever } } catch (ThreadInterrup tedException) { // Perform cleanup - then return return; }
No, I don't agree with that. It means that you don't really know where
you were when you were interrupted. I prefer to still use an orderly
stopping procedure, but do it in a thread-safe way.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: m |
last post by:
Hello,
I have an application that processes thousands of files each day. The
filenames and various related file information is retrieved, related
filenames are associate and placed in a linked list within a single object,
which is then placed on a stack(This cuts down thread creation and deletions
roughly by a factor of 4). I create up to 12 threads, which then process a
single object off of the stack. I use a loop with a boolean...
|
by: Tony Liu |
last post by:
Hi, how can I create multiple new file handles of a file without having to
share to file to the other processes?
I have a file that will be accessed by multiple threads in my application,
each time a thread try to do something with the file, the thread will create
a new file handle. However, if I specify FileShare.ReadWrite, other process
can also open that file. I tried FileShare.Inheritable but it doesn't work.
The reason I needs to...
|
by: Quiet Man |
last post by:
Hi all,
I'm designing a fairly simple service that will run on W2K/SP4 and W2K3
servers. It's job is to be a very specialized database server that listens
on a given IP address / TCP port and handles multiple connections. Client
programs will make a connection and pass text strings to the service, which
will then return a value for each of the strings. It's unlikely the service
will ever have more than 100 simultaneous connections and...
|
by: Oenone |
last post by:
I'm upgrading a DLL from VB6 to VB.NET. The DLL gets called from an ASP.NET
web application.
In the VB6 code there is a module-level object which stores the context
about what the user is doing during each page request. This object is
initialised at the start of each request and populated with various data
retrieved from the URL, and is then repeatedly queried throughout the rest
of the page generation.
Am I right in thinking that...
|
by: Tumurbaatar S. |
last post by:
ASP.NET QuickStart Tutorial says that:
....
ASP.NET maintains a pool of HttpApplication instances over the course of a
Web application's lifetime. ASP.NET automatically assigns one of these
instances to process each incoming HTTP request that is received by the
application. The particular HttpApplication instance assigned is responsible
for managing the entire lifetime of the request and is reused only after the
request has been...
| |
by: gnassar |
last post by:
Hello,
I've written to this group a couple times and would like to initially
start by thanking those who reply to the posts. I seem to be having
some issues that are out of my understanding at the moment and
hopefully someone knowledgeable will be able to guide me the right way.
I have created a program that utilizes three threads minimum. The
initial gui thread, and two worker threads. I haven't set the worker
threads as background...
|
by: Milsnips |
last post by:
hi there,
i created a little test application to send out multiple emails to
addresses, but using threads.
So anyway, what i've got is 1 form with a START button, and a multiline
textbox for recording log output of sending results.
I use the code:
System.Threading.Thread t = new System.Threading.Thread(new
|
by: skip |
last post by:
This question was posed to me today. Given a C/C++ program we can clearly
embed a Python interpreter in it. Is it possible to fire up multiple
interpreters in multiple threads? For example:
C++ main
thread 1
Py_Initialize()
thread 2
Py_Initialize()
|
by: raylopez99 |
last post by:
Compound question: first, and this is not easy, if there's a way to
detect multiple simultaneous key presses in C# let me know (in the
below code, keys c and d being pressed simultaneously or nearly so).
I researched this and for C# (as opposed to MFC) there is no library
function, and no easy way, though some code on the net suggested that
you set up a thread that 'lives' for a certain time, then, if keys are
pressed in that certain...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |