473,324 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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?
Jan 25 '06 #1
5 15404
"Mika M" <ma***************@luukku.com> schrieb
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?

...and why? If you set it to false, you'll get unpredictable results. The
topic you quoted describes this very well.
If you really need to:

Control.CheckForIllegalCrossThreadCalls = False
Armin

Jan 25 '06 #2
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.

--
Mika
Jan 26 '06 #3
"Mika M" <ma***************@luukku.com> schrieb:
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.


Instead of setting 'ReaderData' directly from the thread use
'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/>

Jan 26 '06 #4
"Mika M" <ma***************@luukku.com> schrieb
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.

Use the control's Invoke/BeginInvoke method to marshal the call to the
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

Jan 26 '06 #5
Mika M wrote:
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.


I'm still trying to solve this like this way...

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.
Jan 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: NickP | last post by:
Hi there, This might sound like a stupid question but this whole exception being thrown when accessing user controls from another thread is extremely over the top! Just looking at the index...
10
by: Daniel | last post by:
Hi guys I have a form with my gui on, just some list boxes. And a class that handles incoming data. i want to, on receiving data, update my gui. However even though i have an instance...
10
by: Sergei | last post by:
Can anyone explain why PostMessage to a Windows Form is considered unsafe and raises InvalidOperationException? I can get rid of that setting CheckForIllegalCrossThreadCalls to false and...
3
by: TClancey | last post by:
I'm confused! Probably becuase I know little about threads, and really should. But... I have a serial port control, when it reads data I want to update several things, database fields and...
1
by: CharChabil | last post by:
Hello Guys, I am trying to mark locations on a map (x,y pixels are derived from a DB) This is the code that i am using Private Sub DisplayOnSoftMap() SqlQuey = "Select * FROM SoftwareMap WHERE...
4
by: =?Utf-8?B?amV6MTIzNDU2?= | last post by:
Hi Experts I have a C# Windows application where sometimes it can take upto 20 seconds to switch between different forms. At the moment I show a 'Processing, please wait' dialog while the next...
3
by: sekarm | last post by:
Dear guys, In C# windows application i am using four threads for seperate process. Each thread done seperate job.i want to monitor the thread process in main windows form.so each...
5
by: CCLeasing | last post by:
For an application I'm creating I want to create a 'fake' progress bar. By fake I mean a progress bar that looks like it's doing something but actually isn't. I know philosophically this isn't...
1
by: denisdoherty | last post by:
I am running a stand alone application where i am connecting the clients to the server. I can start up the server but when i try and connect the client to the server it is throwing me up and...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.