473,804 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cross-thread operation problem for RTF control when used in a thre

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.EventArg s) Handles tmrAutoRecover. Tick
Dim t As New Threading.Threa d(New Threading.Threa dStart(AddressO f
delDoAutoBackup ))
t.IsBackground = True
t.Start()
End Sub

Private Sub delDoAutoBackup ()
Dim sRTF As String
sRTF = Me.rtfUser.Rtf
WriteAutoRecove rRecord(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.
Dec 22 '05 #1
2 1339
i tried the code you pasted here but i didnt get any error. anyways try
control.Invok() property to get the text. for that you have to define
one method on form that will return you the text. call that method
using control.Invok method. it should work. this is the only way i'm
telling you. by optimizing it you can get more accurate results.

Dec 22 '05 #2
To Lucky: You must not have been using VS 2005. Information in MSDN appears
to verify this behavior. Microsoft has added the Backgroundworke r control
to handle this situation.

I did more searching and found the following article:
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio .v80.en/dv_fxmclictl/html/138f38b6-1099-4fd5-910c-390b41cbad35.ht m

Below are two examples of code that solves my problem. One uses a delegate.
One uses the backgroundworke r control.

Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
Me.backgroundWo rker1.RunWorker Async()
End Sub

Private Sub backgroundWorke r1_RunWorkerCom pleted(ByVal sender As Object,
ByVal e As RunWorkerComple tedEventArgs) Handles
backgroundWorke r1.RunWorkerCom pleted
Dim s As String = Me.RichTextBox1 .Rtf
Debug.Print(s)
End Sub

=============== =============== =

Delegate Sub ReadRTFCallback ()

Private Sub setTextSafeBtn_ Click(ByVal sender As Object, ByVal e As
EventArgs) Handles setTextSafeBtn. Click
Me.demoThread = New Thread(New ThreadStart(Add ressOf
Me.ThreadProcSa fe))
Me.demoThread.S tart()
End Sub

Private Sub ThreadProcSafe( )
Me.ReadRTF()
End Sub
Private Sub ReadRTF()
If Me.RichTextBox1 .InvokeRequired Then
Dim d As New ReadRTFCallback (AddressOf ReadRTF)
Me.Invoke(d, New Object() {})
Else
Dim s As String = Me.RichTextBox1 .Rtf
Debug.Print(s)
End If
End Sub

Dec 22 '05 #3

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

Similar topics

2
1847
by: Karsten | last post by:
Hi I'm a really a new with this cross platform development, so I have some dumb questions, which I hope you can help me with. If there is a better newsgroup for this question, please point me to it.
7
4844
by: Web Master | last post by:
Are there any good websites or books that deal with cross platform XML? I'd like to target Internet Explorer/Netscape Navigator 5 or later, as well as Opera, possibly konqueror on Linux as well. OT: I'm also looking for books and websites for cross platform XHTML and DHTML.
12
3886
by: * ProteanThread * | last post by:
but depends upon the clique: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=954drf%24oca%241%40agate.berkeley.edu&rnum=2&prev=/groups%3Fq%3D%2522cross%2Bposting%2Bversus%2Bmulti%2Bposting%2522%26ie%3DUTF-8%26oe%3DUTF-8%26hl%3Den ...
6
13171
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get: the two arrays {"one","two","three"},{"red","green","blue} the result one red one green
7
2641
by: Charles | last post by:
I'd like to develop a simple cross-platform application in C++. I'd like it to run in Windows, OS X, PC-BSD and Linux. From my research, it seems I should use Qt or Gtk as a graphical library. Do you agree? Do you have other tips? How Cygwin could help me? Thanks.
6
8638
by: Simon | last post by:
Hi All, An experiment i'm doing requires requires a synchronous cross-domain request, without using a proxy. I wondered if anyone had any ideas to help me achieve this. Below is what I have tried, including my conclusions/assumptions (which i'll happily be corrected on if it solves my problem!): The requirement not to use a proxy means I can't use the synchronous
6
1641
by: brandon.e.taylor | last post by:
I am looking for a tool capable of producing HTML pages from source files written in different languages, where the source written in one language is a port of the source written in another language. Primarily, I need to be able to create hyperlinks - e.g. through the use of tagged comments in the source - linking corresponding code, all the way down to the statement level, between the original source codebase and the ported
12
3568
by: Acrobatic | last post by:
I'm trying to store user passwords in a MySQL database. I learned the hard way that using MySQL "DECODE" and "ENCODE" doesn't seem to work cross-platform, but if I encrypt on the server side with PHP's md5 function, will it work cross-platform (or cross-processor?) Thank you for any advice
1
1442
by: Roumen Petrov | last post by:
Hi list members, It seems to me that this is discussed many times in the past but without progress. As I understand in general there is no objections and preferred cross-compilation has to be based on distutils (scons was rejected). So I would like to cross-compile from linux(build system) to the mingw(host system) and note some(many) problems:
6
3995
by: ampo | last post by:
Hello. Can anyone help with cross-domain problem? I have HTML page from server1 that send xmlHTTPRequest to server2. How can I do it? Thanks.
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10351
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.