Im using a gmail class so that my app can send me notification over gmail.
Its done like this:
public static void SendMessage(string message) { Notification.message = message; Thread t = new Thread(new ThreadStart(SendMessageThreaded)); t.Start(); }
and the threaded function look like this:
private static void SendMessageThreaded() { try { if (Notification.message != "") RC.Gmail.GmailMessage.SendFromGmail("accname", "accpass", "email", "subject", Notification.message); Notification.message = ""; } catch { } }
So after SendMessageThreaded
is run, does it close by itself or do i have to
t.Start() t.Abort()
or something?
A thread is automatically destroyed when the run() method has completed. But it might be required to kill/stop a thread before it has completed its life cycle. Previously, methods suspend(), resume() and stop() were used to manage the execution of threads.
A single thread can exit in three ways, thereby stopping its flow of control, without terminating the entire process. The thread can simply return from the start routine. The return value is the thread's exit code.
Whenever we want to stop a thread from running state by calling stop() method of Thread class in Java. This method stops the execution of a running thread and removes it from the waiting threads pool and garbage collected. A thread will also move to the dead state automatically when it reaches the end of its method.
Use Thread. Join(TimeSpan. Zero) It will not block the caller and returns a value indicating whether the thread has completed its work.
The thread needs to be started once - at which point it will execute the code block assigned to it and exit.
You don't need to explicitly clean up the thread in most cases (unless you want to bail out early for example )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With