473,394 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Closing out threads

Maybe I'm making some assumptions about how threads work. I have a
form that, on the press of a button, starts monitoring some SMTP
connections. On occasions I make changes while the thread is running
in the background. To reload the changed options I have to exit the
function the thread is running and restart it. I have an indicator
that tells me the function is exiting. But on restart I get an
exception that, to the best of my understanding, says that the thread
is still running and cannot be restarted.

So, does the thread keep running after I exit the function? Or is
there something I should be doing to tell the thread to terminate? Do
I need to design the function to run the thread until program's end
but read flags from the UI to stop and reload options?

TIA,
Lilith
Sep 1 '07 #1
3 1576

"Lilith" <li****@dcccd.eduwrote in message
news:2q********************************@4ax.com...
Maybe I'm making some assumptions about how threads work. I have a
form that, on the press of a button, starts monitoring some SMTP
connections. On occasions I make changes while the thread is running
in the background. To reload the changed options I have to exit the
function the thread is running and restart it. I have an indicator
that tells me the function is exiting. But on restart I get an
exception that, to the best of my understanding, says that the thread
is still running and cannot be restarted.
What is the exception?
>
So, does the thread keep running after I exit the function? Or is
there something I should be doing to tell the thread to terminate? Do
I need to design the function to run the thread until program's end
but read flags from the UI to stop and reload options?
You can't restart a thread after it has exited. You have to start a new
thread. If you want to keep the same thread running, then what you ought to
do is have some sort of queue that it can access (using some sort of locking
mechanism like lock() or Monitor.Enter()/Monitor.Exit()) and simply have it
periodically check to see if there's information it needs, but don't have it
exit until the app is done.

Alternatively, you can simply let the thread close and fire off a new thread
in its place..

Sep 1 '07 #2
How are you currently telling the function running the thread, from the main
app, that the function needs to exit?

It would seem that the executing function just needs to check the settings
as it progresses, rather than restarting it with new settings.

Sep 1 '07 #3
On Fri, 31 Aug 2007 20:08:01 -0700, ModelBuilder
<Mo**********@discussions.microsoft.comwrote:
>"Lilith" wrote:
>On Fri, 31 Aug 2007 19:10:00 -0700, ModelBuilder
<Mo**********@discussions.microsoft.comwrote:
>How are you currently telling the function running the thread, from the main
app, that the function needs to exit?
>Probably in a most inappropriate way. :-)
>OK, I vote for unorthodox, but not necessarilly inappropriate... :-)
I try to be inventive with visuals even though anything I write is
generally limited to a small audience. In this case it was a matter
of one button to rule them all.

--
Lilith
Sep 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the...
4
by: muscha | last post by:
Hi, I spawns a number of background threads while creating a windows forms application. I noticed that when I quit the application or calling Application.Exit, it hasn't really stop. Is there a...
6
by: Gary Miller | last post by:
Does anyone know how to detect a modeless form on closing by the form that invoked the modeless form? form.Show();
3
by: Sagaert Johan | last post by:
Hi If i have a form application that creates a thread, is there a way to detect from within that thread if i have closed the form ? Now i use the forms closing event to end the thread i...
1
by: LordHog | last post by:
Hello all, I am a small application that I am developing which will use a few threads. When the user closes the form the threads will remain present until I close them. The Main Form...
22
by: JPSutor | last post by:
when I use the AppDomain.UnLoad method (which calls the Thread.Abort method), I get the following error message AppDomain can not be unloaded because the thread 1378 can not be unwound out of it...
4
by: Funke | last post by:
Assume that in C#, I create a server socket (listener) and code to start new threads with each connection using BeginAccept(). After some time, I have three threads running, each with their own...
22
by: Zytan | last post by:
I have public methods in a form. The main form calls them, to update that form's display. This form is like a real-time view of data that is changing. But, the form may not exist (it is...
1
by: John Vottero | last post by:
If I create a synchronized TextWriter with TextWriter.Synchronized(...), how do I make sure that all the writes are done before I Close()? Do I have to invent that synchronization mechanism...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.