Oppure

Loading
20/06/11 23:21
Sparvier0
Salve,

sono alle prese con il seguente errore:

An attempt has been made to free an RCW that is in use. The RCW is in use on the active thread or another thread. Attempting to free an in-use RCW can cause corruption or data loss.

e si verifica in questo punto del codice:
[CODE]
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
try
{
Form1.deviceAI.Dispose();
Form1.deviceDIO.Dispose();
TimerGiriMotore.Dispose();
TimerPressione.Dispose();
StartTh.Abort();
}
catch
{

}
finally
{
Application.Exit();
}
}

[/CODE]
In particolare qui:

Form1.deviceAI.Dispose();
Form1.deviceDIO.Dispose();

L'errore non si verifica sempre.

Saèreste aiutarmi? Grazie.
Ultima modifica effettuata da Sparvier0 20/06/11 23:21
aaa
21/06/11 8:12
HeDo
prova ad invertire l'ordine delle istruzioni, è probabile che il thread usi quelle risorse e, seppur per qualche msec, glie le stai distruggendo mentre è in funzione:

StartTh.Abort(); 
TimerGiriMotore.Dispose();
TimerPressione.Dispose();  
Form1.deviceAI.Dispose(); 
Form1.deviceDIO.Dispose(); 
aaa