G
Guest
In simplified form, I have an RTF control and a timer. I use the timer to do
an autoresave for the RFT control every 5 minutes. Here is the abridged code.
Private Sub tmrAutoRecover_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrAutoRecover.Tick
Dim t As New Threading.Thread(New Threading.ThreadStart(AddressOf
delDoAutoBackup))
t.IsBackground = True
t.Start()
End Sub
Private Sub delDoAutoBackup()
Dim sRTF As String
sRTF = Me.rtfUser.Rtf
WriteAutoRecoverRecord(sRTF) 'Saves to database table
End Sub
This code works as expected in VS 2003 but returns "Cross-thread operation
not valid" error in VS 2005 when populating the sRTF variable. I understand
the problems with multiple threads accessing a control. In my case the
AutoBackup delegate does not change any RTF control property. It only reads
the RTF property.
Is there a way to disable this protection that Microsoft added to VS 2005
that is not needed for my situation? Is there a better way to accomplish this
backup task? One way that works is to make the sRTF variable class level and
set it in the tmrAutoRecover_Tick method before launching the thread.
Unfortunately, if the RTF contains images, it causes a noticeable delay.
Another solution is to stay with VS 2003.
an autoresave for the RFT control every 5 minutes. Here is the abridged code.
Private Sub tmrAutoRecover_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrAutoRecover.Tick
Dim t As New Threading.Thread(New Threading.ThreadStart(AddressOf
delDoAutoBackup))
t.IsBackground = True
t.Start()
End Sub
Private Sub delDoAutoBackup()
Dim sRTF As String
sRTF = Me.rtfUser.Rtf
WriteAutoRecoverRecord(sRTF) 'Saves to database table
End Sub
This code works as expected in VS 2003 but returns "Cross-thread operation
not valid" error in VS 2005 when populating the sRTF variable. I understand
the problems with multiple threads accessing a control. In my case the
AutoBackup delegate does not change any RTF control property. It only reads
the RTF property.
Is there a way to disable this protection that Microsoft added to VS 2005
that is not needed for my situation? Is there a better way to accomplish this
backup task? One way that works is to make the sRTF variable class level and
set it in the tmrAutoRecover_Tick method before launching the thread.
Unfortunately, if the RTF contains images, it causes a noticeable delay.
Another solution is to stay with VS 2003.