Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My component richtextbox named rtbEditGcode,i used rtbEditGcode_TextChanged to check if richtextbox's content is changed.if content is changed,i use savefile function to store content,but sometimes it throw ioexception.

how can i slove this question?

What I have tried:

i don't know how to tried,thanks for answer.
Posted
Updated 21-Jun-16 0:16am
Comments
JayantaChatterjee 21-Jun-16 6:08am    
I think its the wrong process to save the RichTextBox content on TextChanged event, because it will fire every time when you change(typeing or deleteing) the text in the RichTextBox..
You can try to create a timer or Button to save the Content..
What are IOException error Message?
CHill60 21-Jun-16 6:08am    
"sometimes" - precisely when does it throw the exception?
What is the actual exception?
Share the code you are using

1 solution

My best guess - and without running your code here a guess is all it can be - is that the SaveFile method is asynchronous: it kicks off a thread to do the saving and returns immediately. If so, then your IOException would be because the file is in use from the last save because the TextChanged event fired again immediately the current event ended.

As JayanaChatterjee says, the TextChanged event is a bad place to save info as it can change pretty quickly if the user is a good typist!
I'd suggest that a "IsDirty" flag set in the TextChanged event and checked in a Timer would be a better approach. Set the Timer to an interval of 60000 and reset the flag when you save. Normally, I'd suggest a thread to handle this, but since you can't access the Controls on a different thread, it would just mean Invoking the request back to the main thread anyway in order to do the save!
 
Share this answer
 
Comments
JayantaChatterjee 21-Jun-16 6:21am    
Exactly what I am trying to say..
thanks for Explanation Sir....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900