I'm using a WPF Textbox in Winforms using elementhost to get the SpellChecker feature. I loaded a large text file with at least 100,000 + characters and over 2,000 lines. It opens the file and adds the text to the wpf textbox normally and I can easily scroll through the textbox. When I minimize the program while I've loaded this document, the program gets stuck and it takes quite a while atleast 1 minute(or more sometimes) to maximize back. Nothing wrong with the document or the way the program open the document I just don't understand what's wrong with it. What can be the problem if so, is anyone able to solve this.

I debugged the program and there are no debug errors just performance I guess but it loads and opens fine just when I minimize.

Code for Opening a File:

''
    Dim WpfTest1 As New sp.Tb
    Dim ElementHost1 As System.Windows.Forms.Integration.ElementHost = Me.Controls("ElementHost1")
    Dim TheTextBox As System.Windows.Controls.TextBox = CType(ElementHost1.Child, Tb).ctrl_TextBox
    ''
    Dim OFD As New OpenFileDialog
    OFD.Title = "Open"
    OFD.Filter = "Text Documents (*.txt) | *.txt|All Files |*.*"

    If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
        Using sr As New StreamReader(OFD.FileName, Encoding.Default)
            TheTextBox.Text = sr.ReadToEnd
            Var.SaveLocation = OFD.FileName
            sr.Close()
            Var.MadeChanges = False
            lbl_LastSaved.IsLink = True
        End Using
        Me.Text = System.IO.Path.GetFileNameWithoutExtension(OFD.FileName) + " - " + ProductName
        lbl_LastSaved.Text = "Last Saved " + System.IO.File.GetLastWriteTime(Var.SaveLocation).ToString("f")
        SaveRecentFile(Var.SaveLocation)
    End If

Recommended Answers

All 5 Replies

When I minimize the program while I've loaded this document, the program gets stuck and it takes quite a while atleast 1 minute(or more sometimes) to maximize back.

From my point of view, this a threading problem.

Here you are trying to open a text file. So do not understand why are you trying to save the file SaveRecentFile(Var.SaveLocation).

From my point of view, this a threading problem.

Here you are trying to open a text file. So do not understand why are you trying to save the file SaveRecentFile(Var.SaveLocation).

Nop. Didn't work. I disabled that feature. Essentially it's a different stream to read and write (it saves the opened document into a Recent.txt so it will be displayed in the Recents Menu). Do you have any other suggestions?

@Beta_1 No threading issues here.
Use the Profiler to determine where the bottleneck is.
Hint: it's not in the program logic.
I would question why 100,000+ characters are being loaded into a textbox.
I would also question why you are using Winforms & not WPF for ALL of this application.
What exactly is this program's purpose?

No threading issues here.
Use the Profiler to determine where the bottleneck is.
Hint: it's not in the program logic.
I would question why 100,000+ characters are being loaded into a textbox.
I would also question why you are using Winforms & not WPF for ALL of this application.
What exactly is this program's purpose?

I managed to solve this however, after I did (I'm now using WPF and the program is a simple Text Editor) I'm suffering quite a bit of performance issues when I load a textfile which is atleast 500 kb. Is there anyway how I can get rid of the performance issues? This only happens when I load large textfiles.

I managed to solve this however, after I did (I'm now using WPF and the program is a simple Text Editor) I'm suffering quite a bit of performance issues when I load a textfile which is atleast 500 kb. Is there anyway how I can get rid of the performance issues? This only happens when I load large textfiles.

You did? seems like you're facing a similar problem. I too found a solution and it was to do with the scroll bars, Performance wise it's really slow when typing when I load a large file atleast 1 mb or so. I can realte to the 500 kb too since that problem mostly occurs when it has a LOT

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.