Click here to Skip to main content
16,011,170 members
Home / Discussions / C#
   

C#

 
GeneralRe: SQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
Eddy Vluggen27-Sep-11 8:19
professionalEddy Vluggen27-Sep-11 8:19 
GeneralRe: SQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
kutbinayi27-Sep-11 8:29
kutbinayi27-Sep-11 8:29 
AnswerRe: SQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
Eddy Vluggen27-Sep-11 8:35
professionalEddy Vluggen27-Sep-11 8:35 
GeneralRe: SQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
kutbinayi27-Sep-11 8:48
kutbinayi27-Sep-11 8:48 
GeneralRe: SQL SERVER 2008 Express Backup and Restore using SMO does not effect database Pin
Eddy Vluggen27-Sep-11 11:55
professionalEddy Vluggen27-Sep-11 11:55 
Question(Rich)TextBox problem! Pin
OlivierPD27-Sep-11 4:07
OlivierPD27-Sep-11 4:07 
AnswerRe: (Rich)TextBox problem! Pin
Luc Pattyn27-Sep-11 4:21
sitebuilderLuc Pattyn27-Sep-11 4:21 
GeneralRe: (Rich)TextBox problem! Pin
OlivierPD27-Sep-11 6:25
OlivierPD27-Sep-11 6:25 
Hi,

The Program controls a spectrometer via serail port and triggers multiple measuremets and than collects and processes the results. And it works fine... except the textBox which does not show the ComPortLog in the Program correctly.

to 1: there is already a routine which saves the Log to a File and it also works fine. The textfile contains the complete log string.

to 2: already done... almost every possible exception is catched and written to the trace.

The serialport Communication isn't the problem (i think) because it works without problems, like the whole program. The measurement results are all valid...

I use an own ComPort Class and not the .Net SerialPort due to its unreliability.
If data is send or recieved an Event is fired
C#
public event Action<string> OnSendReceive;

C#
if (OnSendReceive != null)
  OnSendReceive(ComPort.PortName + ": Recieved: " + message);
C#
if (OnSendReceive != null)
  OnSendReceive(ComPort.PortName + ": Send: " + command);

these Events are handled by a DeviceManager Class which then adds a Timestamp to the string and calls the writeline Method of a global instance (defined in MDI ParentForm) of the following class:
C#
public class LogString {
        public delegate void changedEvent();
        public event changedEvent PropertyChanged;
        private StringBuilder log;
        public string Log { get { return log.ToString(); } }
        public int Length { get { return log.Length; } } 
        public string BackupFileName { get; set; }
        public LogString(string InitialString = null) {
            BackupFileName = null;
            log = new StringBuilder(InitialString);
        }
        public override string ToString() {
            return log.ToString();
        }
        public void Write(string txt) { 
            log.Append(txt);
            UpdateFile(); 
            FireEvent(); 
        }
        public void WriteLine(string txt) {  
            log.AppendLine(txt);  
            UpdateFile(); 
            FireEvent(); 
        }
        public void ClearLog() { log.Clear(); FireEvent(); }
        public bool SaveToFile(string FileName, FileMode FMode) {
            try {
                using (Stream Str = new FileStream(FileName, FMode))
                    using (TextWriter TW = new StreamWriter(Str))
                        TW.Write(this.log.ToString());
            } catch { return false; }
            return true;
        }
        private void UpdateFile() {
             if (BackupFileName != null) {
                using (Stream Str = new FileStream(BackupFileName, FileMode.Append))
                    using (TextWriter TW = new StreamWriter(Str))
                        TW.Write(message);
            }
        }
        private void FireEvent() {
            if (PropertyChanged != null) PropertyChanged();
        }
    }

So the Log is written to a File on the Disk an the PropertyChanged Event is fired.

there is a separate Form, which shows the Logs in TextBoxes:
C#
public partial class LogWindow : Form {
        private Tools.StringTraceListener STL;
        private MainWindow parent;
        private MethodInvoker ComPortLogChanged, ProgramLogChanged;
        private string ComPortLog = string.Empty, ProgramLog = string.Empty;
        public LogWindow(Tools.StringTraceListener st, MainWindow p) {
            InitializeComponent();
            parent = p;
            STL = st;
            STL.PropertyChanged += new PropertyChangedEventHandler(STL_PropertyChanged);
            parent.ComPortLog.PropertyChanged += new Classes.Tools.LogString.changedEvent(ComPortLog_PropertyChangedEvent);
            this.CreateHandle();
            ComPortLogChanged = delegate {
                textBox2.Text = ComPortLog;
                textBox2.SelectionStart = textBox2.Text.Length;
                textBox2.ScrollToCaret();
            };
            ProgramLogChanged = delegate {
                textBox1.Text = ProgramLog;
                textBox1.SelectionStart = textBox1.Text.Length;
                textBox1.ScrollToCaret();
            };
        }
        void ComPortLog_PropertyChangedEvent() {
            ComPortLog = string.Empty;
            ComPortLog = parent.ComPortLog.Log;
            if (this.InvokeRequired) Invoke(ComPortLogChanged);
            else ComPortLogChanged();
        }
        void STL_PropertyChanged(object sender, PropertyChangedEventArgs e) {
            ProgramLog = string.Empty;
            ProgramLog = STL.Trace;
            if (this.InvokeRequired) Invoke(ProgramLogChanged);
            else ProgramLogChanged();
        }
}

This works fine for a while and the Log in the Textbox looks like this:
...
27.09.2011 18:12:37 COM3: Recieved: !01 000000 000071 000291 000106 000150
27.09.2011 18:12:37 COM3:     Send: #01c170
27.09.2011 18:12:39 COM3: Recieved: !01 000000 000170 000235 000202 000289
27.09.2011 18:12:39 COM3:     Send: #01c171
27.09.2011 18:12:41 COM3: Recieved: !01 000000 000171 000502 000202 000305
27.09.2011 18:12:41 COM3:     Send: #01c172
27.09.2011 18:12:44 COM3: Recieved: !01 000000 000172 000521 000203 000309
27.09.2011 18:12:44 COM3:     Send: #01c650
27.09.2011 18:12:46 COM3: Recieved: !01 000000 000650 000081 002057 002081
27.09.2011 18:12:46 COM3:     Send: #01c651
27.09.2011 18:12:48 COM3: Recieved: !01 000000 000651 000200 002049 002079
27.09.2011 18:12:48 COM3:     Send: #01c652
27.09.2011 18:12:50 COM3: Recieved: !01 000000 000652 000207 002046 002088
27.09.2011 18:12:51 COM3:     Send: #01c070
27.09.2011 18:12:54 COM3: Recieved: !01 000000 000070 000126 000105 000138
27.09.2011 18:12:54 COM3:     Send: #01c071
27.09.2011 18:12:56 COM3: Recieved: !01 000000 000071 000289 000105 000151
27.09.2011 18:12:56 COM3:     Send: #01c170
27.09.2011 18:12:58 COM3: Recieved: !01 000000 000170 000199 000201 000299
27.09.2011 18:12:58 COM3:     Send: #01c171
27.09.2011 18:13:01 COM3: Recieved: !01 000000 000171 000503 000201 000303
27.09.2011 18:13:01 COM3:     Send: #01c172
27.09.2011 18:13:03 COM3: Recieved: !01 000000 000172 000538 000201 000317
27.09.2011 18:13:03 COM3:     Send: #01c650
27.09.2011 18:13:05 COM3: Recieved: !01 000000 000650 000077 002045 002070
27.09.2011 18:13:05 COM3:     Send: #01c651
27.09.2011 18:13:07 COM3: Recieved: !01 000000 000651 000202 002044 002075
27.09.2011 18:13:08 COM3:     Send: #01c652
27.09.2011 18:13:10 COM3: Recieved: !01 000000 000652 000205 002049 002078
27.09.2011 18:13:11 COM3:     Send: #01c070
27.09.2011 18:13:13 COM3: Recieved: !01 000000 000070 000119 000106 000146
27.09.2011 18:13:13 COM3:     Send: #01c071
27.09.2011 18:13:15 COM3: Recieved: !01 000000 000071 000292 000106 000143
27.09.2011 18:13:15 COM3:     Send: #01c170
27.09.2011 18:13:18 COM3: Recieved: !01 000000 000170 000221 000202 000300
27.09.2011 18:13:18 COM3:     Send: #01c171

but after a couple of minutes (up to 30) it stops working, and the Text in the Textbox does not change anymore and seem truncated:
C#
...
27.09.2011 18:14:56 COM3: Recieved: !01 000000 000171 000513 000204 000303
27.09.2011 18:14:56 COM3:     Send: #01c172
27.09.2011 18:14:58 COM3: Recieved: !01 000000 000172 000546 000204 000304
27.09.2011 18:14:59 COM3:     Send: #01c650
27.09.2011 18:15:01 COM3: Recieved: !01 000000 000650 000087 002070 002095
27.09.2011 18:15:01 COM3:     Send: #01c651
27.09.2011 18:15:03 COM3: Recieved: !01 000000 000651 000198 002071 002102
27.09.2011 18:15:03 COM3:     Send: #01c652
27.09.2011 18:15:05 COM3: Recieved: !01 000000 000652 000197 002071 002102
27.09.2011 18:15:06 COM3:     Send: #01c070
27.09.2011 18:15:08 COM3: Recieved: !01 000000 000070 000124 000107 000142
27.09.2011 18:15:09 COM3:     Send: #01c071
27.09.2011 18:15:11 COM3: Recieved: !01 000000 000071 000283 000107 000145
27.09.2011 18:15:11 COM3:     Send: #01c170
27.09.2011 18:15:13 COM3: Recieved: !01 000000 000170 000216 000204 000303
27.09.2011 18:15:13 COM3:     Send: #01c171
27.09.2011 18:15:15 COM3: Recieved: !01 000000 000171 000531 000203 000319
27.09.2011 18:15:15 COM3:     Send: #01c172
27.09.2011 18:15:18 COM3: Recieved: !01 000000 000172 000505 000203 000307
27.09.2011 18:15:18 COM3:     Send: #01c650
27.09.2011 18:15:20 COM3: Recieved: !01 000000 000650 000080 002070 002097
27.09.2011 18:15:20 COM3:     Send: #01c651
27.09.2011 18:15:22 COM3: Recieved: !01 000000 000651 000212 002071 002098
27.09.2011 18:15:22 COM3:     Send: #01c652
27.09.2011 18:15:25 COM3: Recieved: !01 000000 000652 000209 002071 002102
27.09.2011 18:15:26 COM3:     Send: #01c070
27.09.2011 18:15:28 COM3: Recieved: !01 000000 000070 000116 000107 000140
27.09.2011 18:15:28 COM3:     Send: #01c071
27.09.2011 18:15:30 COM3: Recieved: !01 000000 000071 000290 000107 000146
27.09.2011 18:15:30 COM3:     Send: #01c170
27.09.2011 18:15:32 COM3: Recieved: !01 000000 000170 000230 000203 000297
27.09.2011 18:15:32 COM3:     Send: #01c171
27.09.2011 18:15:35 COM3: Recieved: !01 000000 000171 00054 

All the event are fired correctly, and the textbox flashes as it still trys to scroll to the end but Command
C#
textBox2.Text = ComPortLog;
doesn't work correctly... the string ComPortLog contains the complete ComPort Log but the Text Property of the TextBox doesn't...
it is a complete Mystery for me...
GeneralRe: (Rich)TextBox problem! Pin
Pete O'Hanlon27-Sep-11 6:27
mvePete O'Hanlon27-Sep-11 6:27 
GeneralRe: (Rich)TextBox problem! Pin
OlivierPD27-Sep-11 6:41
OlivierPD27-Sep-11 6:41 
AnswerRe: (Rich)TextBox problem! Pin
Luc Pattyn27-Sep-11 7:21
sitebuilderLuc Pattyn27-Sep-11 7:21 
AnswerRe: (Rich)TextBox problem! Pin
BobJanova27-Sep-11 5:15
BobJanova27-Sep-11 5:15 
GeneralRe: (Rich)TextBox problem! Pin
OlivierPD27-Sep-11 6:31
OlivierPD27-Sep-11 6:31 
Questionplz give guideline.. Pin
Pragya727-Sep-11 1:22
Pragya727-Sep-11 1:22 
AnswerRe: plz give guideline.. Pin
Richard MacCutchan27-Sep-11 1:33
mveRichard MacCutchan27-Sep-11 1:33 
GeneralRe: plz give guideline.. Pin
Pragya730-Sep-11 0:16
Pragya730-Sep-11 0:16 
AnswerRe: plz give guideline.. PinPopular
BobJanova27-Sep-11 1:39
BobJanova27-Sep-11 1:39 
AnswerRe: plz give guideline.. Pin
Pete O'Hanlon27-Sep-11 3:02
mvePete O'Hanlon27-Sep-11 3:02 
AnswerRe: plz give guideline.. Pin
RichardGrimmer28-Sep-11 6:25
RichardGrimmer28-Sep-11 6:25 
QuestionC# InvokeRequired into WPF Pin
iresh8827-Sep-11 0:53
iresh8827-Sep-11 0:53 
AnswerRe: C# InvokeRequired into WPF Pin
BobJanova27-Sep-11 1:36
BobJanova27-Sep-11 1:36 
GeneralRe: C# InvokeRequired into WPF Pin
Ian Shlasko27-Sep-11 2:57
Ian Shlasko27-Sep-11 2:57 
GeneralRe: C# InvokeRequired into WPF Pin
iresh8827-Sep-11 4:28
iresh8827-Sep-11 4:28 
GeneralRe: C# InvokeRequired into WPF Pin
BobJanova27-Sep-11 5:15
BobJanova27-Sep-11 5:15 
Questionhow to identify my screen data? Pin
neodeaths26-Sep-11 23:46
neodeaths26-Sep-11 23:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.