Hi!
I am starting up a thread that is listening for tcp connections in the
thread i am using
while (true)
{
// Handle the tcp stuff!!
}
and when i close the main program the thread remains, when i use
myThread.Abort( );
Is there a way to terminate the thread? Or do i have to send data to the
thread
telling that the "While (true)" should be false, and there for the thread is
self terminated?
How can i send data to an ongoing thread?
Any ideas, tips would be welcommed.
Regards
Martin 3 2145
Martin Arvidsson wrote:
Hi!
I am starting up a thread that is listening for tcp connections in the
thread i am using
while (true)
{
// Handle the tcp stuff!!
}
and when i close the main program the thread remains, when i use
myThread.Abort( );
Is there a way to terminate the thread? Or do i have to send data to the
thread
telling that the "While (true)" should be false, and there for the thread is
self terminated?
How can i send data to an ongoing thread?
Any ideas, tips would be welcommed.
Regards
Martin
Hi,
A good place to start is http://msdn2.microsoft.com/en-us/library/7a2f3ay4.aspx
But to summarise you should never really call Abort on a thread. If
your answer to that is what should I do if my thread might be blocked
in an IO call then you should refactor your code to use non blocking
IO.
If you need any more details or some examples drop me a line.
Best,
Nick http://www.seecharp.blogspot.com/
You could also try setting the thread's IsBackground property. When you
exit your process all daemon (background) threads are stopped
automatically.
Jono
nick_nw wrote:
Martin Arvidsson wrote:
Hi!
I am starting up a thread that is listening for tcp connections in the
thread i am using
while (true)
{
// Handle the tcp stuff!!
}
and when i close the main program the thread remains, when i use
myThread.Abort( );
Is there a way to terminate the thread? Or do i have to send data to the
thread
telling that the "While (true)" should be false, and there for the thread is
self terminated?
How can i send data to an ongoing thread?
Any ideas, tips would be welcommed.
Regards
Martin
Hi,
A good place to start is http://msdn2.microsoft.com/en-us/library/7a2f3ay4.aspx
But to summarise you should never really call Abort on a thread. If
your answer to that is what should I do if my thread might be blocked
in an IO call then you should refactor your code to use non blocking
IO.
If you need any more details or some examples drop me a line.
Best,
Nick http://www.seecharp.blogspot.com/
Read this http://laflour.spaces. live.com/blog/cns!7575E2FFC19 135B4!220.entry
point 4)
--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
"Martin Arvidsson" wrote:
Hi Nick!
I have enclosed code, perhaps you can tell right away what i should do.
Regards
Martin
"nick_nw" <ng****@gmail.c omskrev i meddelandet
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
Martin Arvidsson wrote:
Hi!
I am starting up a thread that is listening for tcp connections in the
thread i am using
while (true)
{
// Handle the tcp stuff!!
}
and when i close the main program the thread remains, when i use
myThread.Abort( );
Is there a way to terminate the thread? Or do i have to send data to the
thread
telling that the "While (true)" should be false, and there for the thread
is
self terminated?
How can i send data to an ongoing thread?
Any ideas, tips would be welcommed.
Regards
Martin
Hi,
A good place to start is http://msdn2.microsoft.com/en-us/library/7a2f3ay4.aspx
But to summarise you should never really call Abort on a thread. If
your answer to that is what should I do if my thread might be blocked
in an IO call then you should refactor your code to use non blocking
IO.
If you need any more details or some examples drop me a line.
Best,
Nick http://www.seecharp.blogspot.com/
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: DE |
last post by:
Hello,
I have an app with embedded Python. Python scripts create their own
threads and I need to terminate these threads at the point where the
user wants to leave the application. I use threading.Thread as base
classes.
I have tried to use call the join method of the python thread objects
from C++. But although the call succeeds, the threads don't exit.
|
by: Byron |
last post by:
I'm new to C# and threading, so hopefully this is a simple newbie question.
I have a form that is supposed to listen for network traffic on a given port
and decode and display any interesting traffic it sees. To do this I've
launched a separate thread to do the listening.
When I run my form it seems to work fine, but when I close the form the
thread is not being terminated and Task Manager shows the application process
still...
|
by: Dave |
last post by:
I have an application that queries SQL Server and Index Server using ADO.
I'd like to have a feature where a user can cancel a long-running query.
What I plan on doing is to move my query code to a worker thread which will
then post a message back to the main thread when it's done. Then, the
application can have a button that a user can press to terminate the worker
thread. That way, the app stays responsive during a long-running query. ...
|
by: Adam Clauss |
last post by:
I have a C# Windows Service running as the NetworkService account because it
needs to access a network share.
As part of the service's initialization, I want the service to terminate, if
an unrecoverable error occurs. When that case occurs, I create a
ServiceController object and call the Stop() method.
However - I get an exception thrown saying access denied. If I switch to
using the LocalService account it works fine, but I lose...
|
by: Tomaz Koritnik |
last post by:
I have a class that runs one of it's method in another thread. I use Thread
object to do this and inside ThreadMethod I have an infinite loop:
While (true)
{
// do something
Thread.Sleep(100);
}
The problem is that I don't know how to terminate the thread when my class
| |
by: Aaron Gray |
last post by:
Hi,
I have some code I just cannot seem to get to work properly on FireFox. It
is probably something simple.
On FireFox the following code does not seem to terminate in the browser, but
it works fine on IE :-
http://angray.members.beeb.net/Test/Test5.html
|
by: PhotoLover |
last post by:
I have gotten 3 messages saying,
"Terminating thread due to stack overflow problems. A V&D, possibly recently installed has consumed too much stack space.
Increase the settings of MinSP's in System.INI or remove recently installed V&D's. There are currently 19 SP's allocated."
HELP! Please.
Photo Lover
|
by: masaniparesh |
last post by:
Hi,
In my C# program i am termination thread by thread.Abort when times out occur. But i figured out that even after thread.Abort operation the thread is being alive for the random time. I have given the code snippet for this below.
private void Delay()
{
//Thread waiting for the output stream of the process
DateTime expireTime = DateTime.Now.AddSeconds(30);
Thread outputThread = new Thread(new ThreadStart(ReadOutput));
...
|
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= |
last post by:
Hello,
I have a thread ABC that starts another thread XYX. Thread XYZ monitors
various things and if there is no work to do it calls Thread.Sleep to sleep
for a minute or so. Occasionally thread ABC needs to get thread XYZ's quick
attention. My first attempt at this was to have thread ABC merely set a
global flag variable that thread XYZ would check at specific points in its
execution, and if it saw that the flag was set it would take...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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: 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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |