in_valparaiso
Member
- Joined
- Apr 5, 2019
- Messages
- 13
- Programming Experience
- 10+
I am writing a type of AI chatbot for our organization which allows users to "chat" with the program and ask for help with "I forgot my password", "I lost my J drive" …
Everything works well, but too well. The minute the user asks the question, the response is immediately presented to the user and it seems unnatural. So I added a label that says "Typing ..." and hid it. When it comes time to present the response, I want to make the label visible, wait a period of time, hide the label and move on.
Here's an outline of what the software does
User types question and the input is placed in a richtextbox.
Appropriate response found.
** Show typing **
Add response to richtextbox
** Stop showing typing **
If there were additional comments
** Show typing **
Add additional comments
** Stop showing typing **
...
My logic for ** Show typing ** is:
public static void Typing(string text, Label lbl)
{
lbl.Visible = true;
Thread.Sleep((text.Length / 3) * 1000); // Average person types 3 characters a second. In doing this I can pause the average length of
// time to type the text being shown.
lbl.Visible = false;
}
=====
My issue is: with the code above, when the user types their input it pauses for whatever thread.sleep is set for (even though the method isn't even called at this point. Then after it pauses where it shouldn't, it never pauses again, so the computer response shows up immediately after the first pause. I never see the label made visible. What am I doing wrong? I probably did a horrible job explaining this.
Everything works well, but too well. The minute the user asks the question, the response is immediately presented to the user and it seems unnatural. So I added a label that says "Typing ..." and hid it. When it comes time to present the response, I want to make the label visible, wait a period of time, hide the label and move on.
Here's an outline of what the software does
User types question and the input is placed in a richtextbox.
Appropriate response found.
** Show typing **
Add response to richtextbox
** Stop showing typing **
If there were additional comments
** Show typing **
Add additional comments
** Stop showing typing **
...
My logic for ** Show typing ** is:
public static void Typing(string text, Label lbl)
{
lbl.Visible = true;
Thread.Sleep((text.Length / 3) * 1000); // Average person types 3 characters a second. In doing this I can pause the average length of
// time to type the text being shown.
lbl.Visible = false;
}
=====
My issue is: with the code above, when the user types their input it pauses for whatever thread.sleep is set for (even though the method isn't even called at this point. Then after it pauses where it shouldn't, it never pauses again, so the computer response shows up immediately after the first pause. I never see the label made visible. What am I doing wrong? I probably did a horrible job explaining this.