Ho un modulo che avvia una discussione. Ora voglio che il modulo si chiuda automaticamente quando questo thread termina.Chiamare un metodo alla chiusura del thread
L'unica soluzione che ho trovato finora è aggiungere un timer al modulo e controllare se il thread è attivo su ogni tick. Ma voglio sapere se c'è un modo migliore per farlo?
Attualmente il mio codice sembra più meno così
partial class SyncForm : Form {
Thread tr;
public SyncForm()
{
InitializeComponent();
}
void SyncForm_Load(object sender, EventArgs e)
{
thread = new Thread(new ThreadStart(Synchronize));
thread.IsBackground = true;
thread.Start();
threadTimer.Start();
}
void threadTimer_Tick(object sender, EventArgs e)
{
if (!thread.IsAlive)
{
Close();
}
}
void Synchronize()
{
// code here
}
}
Funziona alla grande, grazie – RaYell