i am in a little bit of a pickle, so about 3 weeks ago i start working on my own wpf project, for some reason when i minimize my window, it crashes (i am just using windowstate to minimize ) and my logging is a usercontrol, i dont see what my problem is, any advice would help.

also whenever i use ScrollToEnd when minimize is also causes error,

here is the error code

Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string message).
Message: Unrecoverable system error.
at System.Environment.FailFast(System.String)
at MS.Internal.Invariant.FailFast(System.String, System.String)
at System.Windows.Documents.SplayTreeNode.get_Role()
at System.Windows.Documents.SplayTreeNode.Splay()
at System.Windows.Documents.SplayTreeNode.GetMinSibling()
at System.Windows.Documents.TextContainer.get_FirstContainedNode()
at System.Windows.Documents.TextElementCollection`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].get_FirstChild()
at System.Windows.Documents.TextElementCollection`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].get_Count()
at Wmanager.Windows.WindowControls.LogView.AppendMessage(System.Windows.Controls.RichTextBox, System.String, System.Drawing.Color)
at Wmanager.Windows.WindowControls.LogView+<>c__DisplayClass1_0.<OnWrite>b__0()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
at System.Threading.Tasks.Task.ExecutionContextCallback(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)
at System.Threading.Tasks.Task.ExecuteEntry(Boolean)
at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

my logview code :

public LogView()
    {
        InitializeComponent();
        Logs.Document.Blocks.Remove(Logs.Document.Blocks.FirstBlock);
        LogEvent.OnWrite += OnWrite;
    }

    private void OnWrite(string message, Color col)
    {
        try
        {
            Task.Run(() => { AppendMessage(Logs, message, col); });
        }
        catch(Exception ex)
        {
            Logging.WriteError($"LogView > OnWrite() > {ex}");
        }
    }
    private static void AppendMessage(RichTextBox textBox, string message, Color col)
    {
        lock(MessageLock)
        {
            try
            {
                if (!textBox.Dispatcher.CheckAccess())
                {
                    textBox.Dispatcher.Invoke(new Action<RichTextBox, string, Color>(AppendMessage), new object[]
                    {
                        textBox,
                        message,
                        col
                    });
                }
                else
                {
                    Paragraph paragraph = new Paragraph(new Run(message));
                    paragraph.Foreground = new System.Windows.Media.SolidColorBrush(new System.Windows.Media.Color
                    {
                        A = col.A,
                        R = col.R,
                        G = col.G,
                        B = col.B
                    });
                    textBox.Document.Blocks.Add(paragraph);
                }
                int Block = 0;
                while (Block <= 200 && textBox.Document.Blocks.Count > 300)
                {
                    textBox.Document.Blocks.Remove(textBox.Document.Blocks.FirstBlock);
                    Block++;
                }
            }
            catch (Exception ex)
            {
                Logging.WriteError(ex.ToString());
            }
        }
    }
    private static object MessageLock = new object();
0

There are 0 answers