I think (as far as I remember) the simple TextBox control is a "simple"
control which should be used for simple purpose. Maybe the RichTextBox
control is a better solution.

Anyway here are some recommendations,

Do NOT put "large text" in the TextBox in one go, this will hang your UI a
little bit. Why? because TextBox control try to render the text in it and
this rendering is done in the main UI thread. Thats why your main UI
gets freezed. Try using

TextBox1.SuspendLayout();
TextBox1.Text = LargeStringVariable;
TextBox1.ResumeLayout();

This may solve your issue.

But,

I think the best solution is to put text through TextBox.AppendText()
method. Here is what you should do,

1) You get a whole large string in a String Variable now you want to put
that value in TextBox
2) Create another thread (backgroundworker) and process that large string in
chunks.
3) Which means create a loop and read each 100 characters from large text
and append them in TextBox using TextBox's AppnedText() method.

Or maybe if you can, try appending the text directly in text box when large
string was being created. In this way you don't have to create the large
string in first place. You will be adding text directly in text box.

P.S. TextBox1.Text += sometext; is a very bad idea.

On Wed, Nov 10, 2010 at 6:45 PM, Michael Busch <
[email protected]> wrote:

> Hi Guys.
>
> I have a problem, hopefully you can help me.
>
> I am working with automation software and on my HMI software I have a small
> performance problem.
> Sometimes it is possible to show the code of a control program, what it
> (sometimes) about 145,000 lines (or more).
>
> It comes out of the control as one string.
>
> I tried to show the code in a textbox, but this takes about one minute to
> show up. My HMI is frozen during the time.
> Yes, I am using a background worker (async), so I dont understand why it
> freezes up the whole HMI.
> (its only the line filling the multiline textbox).
> The code in this case is only one line:
>
> >> textbox1.text = codefromControl.code;
>
>
> So, I changes to code to a stringbuilder, which is filling the textbox.
> I splited the text up in lines, and tried different ways to fill up the
> textbox (trying as less refreshes of the textbox as possible).
>
> The best performance I got was 10,000 lines in 0.7 sec.
> But this means its still 15sec to load the screen (its frozen in all
> scenarios with my background worker, and I dont know why).
>
> So, I need to know
>
> - how can add my controlcode to the textbox with the best performance?
> - some ideas ( I know I dont posted code) why writing to the textbox
> freezes my HMI and why my background worker isnt working?
> - some ideas to increase performace? perhaps different control - listview,
> richtextbox, etc?
> - How can I realize that the screen is loaded, the first e.g. 1000 lines
> are displayed and the rest is loaded in the background ( I tried this out
> for a couple os days, but I got it never running (see the other problems,
> its always freezing up).
>
> Thanks a lot th everybody in advance.
>
> Mike
>
>
>
>
>

Reply via email to