Writing in Textbox freezes form

Asked

Viewed 61 times

0

I have a form that has a Textbox and would like to write in it but give an effect of Typewriter so that the text is not added fully "dry".

I created a method that takes the text I’d like to add and does the effect as expected. However, the form is frozen and only after the writing of all the text is possible to use the form.

    private void escreverMensagem(string msg)
    {
        char[] msg_array = msg.ToArray<char>();

        for (int i = 0; i < msg_array.Length; i++)
        {
            txtMensagens.AppendText(msg_array[i].ToString());
            Thread.Sleep(30);
        }
    }

When I need to add something I will just call it with the desired string.

I believe I should start a new Thread to make the method typeMensage(string msg), but I have no idea what it would look like.

  • The Thread.Sleep is using the same visual thread. In the escreverMensagem you must run it from another thread.

  • @vnbrs In this case every time I call write?

  • If it is executed in the same thread in which your screen is drawn, it will lock.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.