|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
CheckForIllegalCrossThreadCalls ?Help link...
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxmclictl/html/138f38b6-1099-4fd5-910c-390b41cbad35.htm ....says "You can disable this exception by setting the value of the CheckForIllegalCrossThreadCalls property to false. This causes your control to run the same way as it would run under Visual Studio 2003. " I'd like to try setting this property to false, but I don't understand where in the code and how? "Mika M" <mahmik_removet***@luukku.com> schrieb ...and why? If you set it to false, you'll get unpredictable results. The > Help link... > > ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxmclictl/html/138f38b6-1099-4fd5-910c-390b41cbad35.htm > > ...says "You can disable this exception by setting the value of the > CheckForIllegalCrossThreadCalls property to false. This causes your > control to run the same way as it would run under Visual Studio > 2003. " > > I'd like to try setting this property to false, but I don't > understand where in the code and how? topic you quoted describes this very well. If you really need to: Control.CheckForIllegalCrossThreadCalls = False Armin Armin Zingler wrote:
Show quoteHide quote >> ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxmclictl/html/138f38b6-1099-4fd5-910c-390b41cbad35.htm I have made my own class for reading serialport equipment. When >> >> >> ...says "You can disable this exception by setting the value of the >> CheckForIllegalCrossThreadCalls property to false. This causes your >> control to run the same way as it would run under Visual Studio >> 2003. " >> >> I'd like to try setting this property to false, but I don't >> understand where in the code and how? > > > ..and why? If you set it to false, you'll get unpredictable results. > The topic you quoted describes this very well. > serialport receives data, data is saved into public property like... Public Event ReaderDataReceived As EventHandler Private _ReaderData As String = "" Public Property ReaderData() As String Get Return _ReaderData End Get Set(ByVal Value As String) ... _ReaderData = Value ... RaiseEvent ReaderDataReceived(Me, New EventArgs) End Set End Property Private Sub port_DataReceived(...) Handles port.DataReceived '// "port" is instance of Framework 2.0 SerialPort ... Me.ReaderData = port.ReadExisting ... End Sub This ReaderData-property is DataBound into Windows Form TextBox like... txtReaderData.DataBindings.Add("Text", MyClass, "ReaderData") and it seems not to work without setting Control.CheckForIllegalCrossThreadCalls = False Yes I understand it's question about unsafe threads. Handling threads is something new for me, and this application has both class for handling serialport and Windows Form for using class as DataBound way. I can't figure out how to make my applicaton thread safe in this case. -- Mika
Show quote
Hide quote
"Mika M" <mahmik_removet***@luukku.com> schrieb: Instead of setting 'ReaderData' directly from the thread use > Private Sub port_DataReceived(...) Handles port.DataReceived > '// "port" is instance of Framework 2.0 SerialPort > ... > Me.ReaderData = port.ReadExisting > ... > End Sub > > > This ReaderData-property is DataBound into Windows Form TextBox like... > > txtReaderData.DataBindings.Add("Text", MyClass, "ReaderData") > > and it seems not to work without setting > Control.CheckForIllegalCrossThreadCalls = False > > Yes I understand it's question about unsafe threads. Handling threads is > something new for me, and this application has both class for handling > serialport and Windows Form for using class as DataBound way. I can't > figure out how to make my applicaton thread safe in this case. 'Control.Invoke'/'Control.BeginInvoke' to set it. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Show quote
Hide quote
"Mika M" <mahmik_removet***@luukku.com> schrieb Use the control's Invoke/BeginInvoke method to marshal the call to the > Armin Zingler wrote: > > > > ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxmclictl/html/138f38b6-1099-4fd5-910c-390b41cbad35.htm > > > > > > > > > ...says "You can disable this exception by setting the value of > > > the CheckForIllegalCrossThreadCalls property to false. This > > > causes your control to run the same way as it would run under > > > Visual Studio 2003. " > > > > > > I'd like to try setting this property to false, but I don't > > > understand where in the code and how? > > > > > > ..and why? If you set it to false, you'll get unpredictable > > results. The topic you quoted describes this very well. > > > > I have made my own class for reading serialport equipment. When > serialport receives data, data is saved into public property like... > > Public Event ReaderDataReceived As EventHandler > > Private _ReaderData As String = "" > > Public Property ReaderData() As String > Get > Return _ReaderData > End Get > Set(ByVal Value As String) > ... > _ReaderData = Value > ... > > RaiseEvent ReaderDataReceived(Me, New EventArgs) > End Set > End Property > > Private Sub port_DataReceived(...) Handles port.DataReceived > '// "port" is instance of Framework 2.0 SerialPort > ... > Me.ReaderData = port.ReadExisting > ... > End Sub > > > This ReaderData-property is DataBound into Windows Form TextBox > like... > > txtReaderData.DataBindings.Add("Text", MyClass, "ReaderData") > > and it seems not to work without setting > Control.CheckForIllegalCrossThreadCalls = False > > Yes I understand it's question about unsafe threads. Handling > threads is something new for me, and this application has both class > for handling serialport and Windows Form for using class as > DataBound way. I can't figure out how to make my applicaton thread > safe in this case. thread that created the control. See also: Visual Basic Express Visual Basic Programming Guide Multithreading in Visual Basic Multithreading with Forms and Controls ..NET Framework SDK Windows Applications Windows Forms Windows Forms Controls Developing Custom Windows Forms Controls with _ the .NET Framework Multithreading in Windows Forms Controls Armin Mika M wrote:
Show quoteHide quote > Armin Zingler wrote: I'm still trying to solve this like this way...> >>> ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxmclictl/html/138f38b6-1099-4fd5-910c-390b41cbad35.htm >>> >>> >>> ...says "You can disable this exception by setting the value of the >>> CheckForIllegalCrossThreadCalls property to false. This causes your >>> control to run the same way as it would run under Visual Studio >>> 2003. " >>> >>> I'd like to try setting this property to false, but I don't >>> understand where in the code and how? >> >> >> ..and why? If you set it to false, you'll get unpredictable results. >> The topic you quoted describes this very well. >> > > I have made my own class for reading serialport equipment. When > serialport receives data, data is saved into public property like... > > Public Event ReaderDataReceived As EventHandler > > Private _ReaderData As String = "" > > Public Property ReaderData() As String > Get > Return _ReaderData > End Get > Set(ByVal Value As String) > ... > _ReaderData = Value > ... > > RaiseEvent ReaderDataReceived(Me, New EventArgs) > End Set > End Property > > Private Sub port_DataReceived(...) Handles port.DataReceived > '// "port" is instance of Framework 2.0 SerialPort > ... > Me.ReaderData = port.ReadExisting > ... > End Sub > > > This ReaderData-property is DataBound into Windows Form TextBox like... > > txtReaderData.DataBindings.Add("Text", MyClass, "ReaderData") > > and it seems not to work without setting > Control.CheckForIllegalCrossThreadCalls = False > > Yes I understand it's question about unsafe threads. Handling threads is > something new for me, and this application has both class for handling > serialport and Windows Form for using class as DataBound way. I can't > figure out how to make my applicaton thread safe in this case. Public Class MyUIForm Inherits Form Delegate Sub SetTextCallback([text] As String) Private Sub DisplayText(ByVal [text] As String) ' InvokeRequired required compares the thread ID of the ' calling thread to the thread ID of the creating thread. ' If these threads are different, it returns true. If Me.txtReaderData.InvokeRequired Then Dim d As New SetTextCallback(AddressOf DisplayText) Me.Invoke(d, New Object() {[text]}) Else Me.txtReaderData.Text += [text] End If End Sub ....but I don't know how to do binding with txtReaderData-TextBox of the SerialPort reading-classes "ReaderData"-public property. Propably I should not use txtReaderData.DataBindings.Add("Text", MyClass, "ReaderData") any more, but how txtReaderData can notice when "ReaderData"-property value changes? That how to sample code (ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxmclictl/html/138f38b6-1099-4fd5-910c-390b41cbad35.htm) is simply too complex to figure out for someone - read: for me :) - who is not yet familiar with threads handling in my mind.
date/time fields
Conditional statements throw/handle exceptions while using backgroundworker Strange maximize behaviour Queue of Threads What is the correct case convention for Set? How to use a Generic's base type? timing accuracy of VB.Net checkedlistbox and mouseleave event deleting files greater than x days |
|||||||||||||||||||||||