User avatar
Leslie
Lead Software Architect
Posts: 352
Joined: Fri Sep 14, 2012 12:20 pm
Contact: Website

Multi-Threaded Questioning

Thu Oct 02, 2014 6:01 pm

Multi-Threaded question mechanism was used when Syn Virtual Assistant Prototype 7 was released from Prototype 8.0 onward we decided that it was really cumbersome to maintain all the threads in a GUI environment. Since then Multi-Threaded question has been kept in Syn Engine for backward compatibility and research over Multi-Threaded question is halted.

But if you have a multi-threaded environment and the GUI interaction isn't that important you can definitely try the Multi-Threaded question.

Here is a sample for an Exit command to be executed only when the user confirms by saying Yes or No.

CSharp Code

public void ExitApplication(ExitTerm cmd)
{
SynResponse resp = new SynResponse();
resp.Message = "Are you sure ?";
resp.Expecting = "Yes/No";
cmd.Data.Caller.AddQuestionService(() => Application.DoEvents());
if (cmd.Data.Caller.Question(resp).ContainsPattern(SynText.Patterns.Yes) == true)
{
Application.Exit();
}
else
{
cmd.Data.Caller.Respond("Shutdown cancelled");
}
}
In the above command we create a SynResponse which is then sent to the Caller as a question. Then we use the "extended" command ContainsPattern to check if the user has responded that contains the pattern for "Yes". If so then exit the application else we respond "Shutdown cancelled".

Sample code to import extensions

CSharp Code

using Syn.Engine.Extensions;
Since a question is asked in a Multi-Threaded fashion Syn Engine will actually lock the thread until a user response is received. So in a GUI application if the main thread is used to interact with the Engine then probably the main thread will be locked and so will the GUI interaction. Therefore we add the "Application.DoEvents" as an action that should run until a response is received from the user making sure the GUI is still responsive.

Though multi-threaded question requires lesser coding we still encourage Single-Threaded questioning mechanism for thread safety.

Return to “Archived (Old Posts)”

Who is online

Users browsing this forum: No registered users and 1 guest