Hello,
I have made an application that saves data incoming from a serialPort to a *.txt file.
I have basically one button that launchs the whole process.
My application works well when I first launch it. I get the data, save them in the text File, close the streamWriter and disconnect the serial port. The problem comes when I click a second time on the main button, then it should follow the same process a second time, but it seems that the application doesn't want to write to the text file a second time.
Here are the most relevant things :
I connect the serial port before creating a thread that launch the go function adn close it after.
As I said when I fisrt launch the function everything goes well, when I launch the new thread a second time, I get an error while writing the data to the text file in a loop. But it did go well for the first line writing !
It is an ObjectDisposedException "impossible to write in a closed TextWriter".. any guess to go around this problem ?
Thank you in advance
I have made an application that saves data incoming from a serialPort to a *.txt file.
I have basically one button that launchs the whole process.
- serialPort connection
- name or select a file to write in
- create a new streamWriter
- write a line "first line" to the text file
- receive all the data and store them in the text file
- close the stream writer
- close the serial connection
My application works well when I first launch it. I get the data, save them in the text File, close the streamWriter and disconnect the serial port. The problem comes when I click a second time on the main button, then it should follow the same process a second time, but it seems that the application doesn't want to write to the text file a second time.
Here are the most relevant things :
Public Class Export Private _fileName As String Private _objStream As System.IO.StreamWriter Public Sub Go() Main.SaveFileDialog1.ShowDialog() 'name or select a file to write in _fileName = Main.SaveFileDialog1.FileName 'If _fileName <> "" Then process _objStream = New System.IO.StreamWriter(_fileName, True) 'create a new streamWriter 'writting in the first line _objStream.WriteLine("first Line") 'getting the data 'writing the data to the text file in a loop <-- crash here at the second run End Sub
I connect the serial port before creating a thread that launch the go function adn close it after.
As I said when I fisrt launch the function everything goes well, when I launch the new thread a second time, I get an error while writing the data to the text file in a loop. But it did go well for the first line writing !
It is an ObjectDisposedException "impossible to write in a closed TextWriter".. any guess to go around this problem ?
Thank you in advance