Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

SurveyScheduler.cs 1.4 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  1. namespace CreateNewConversationBot
  2. {
  3. using System;
  4. using System.Collections.Concurrent;
  5. using System.Threading.Tasks;
  6. using System.Web.Hosting;
  7. using Microsoft.Bot.Builder.Dialogs;
  8. using Microsoft.Bot.Connector;
  9. [Serializable]
  10. public sealed class SurveyScheduler : ISurveyScheduler
  11. {
  12. private readonly ConcurrentQueue<ConversationReference> surveyRequests = new ConcurrentQueue<ConversationReference>();
  13. public SurveyScheduler()
  14. {
  15. HostingEnvironment.QueueBackgroundWorkItem(async token =>
  16. {
  17. while (true)
  18. {
  19. token.ThrowIfCancellationRequested();
  20. while (surveyRequests.Count > 0)
  21. {
  22. ConversationReference surveyRequest = null;
  23. if (surveyRequests.TryDequeue(out surveyRequest))
  24. {
  25. await SurveyTriggerer.StartSurvey(surveyRequest, token);
  26. }
  27. }
  28. // polling is one of the naive aspects of this implementation
  29. await Task.Delay(TimeSpan.FromSeconds(5));
  30. }
  31. });
  32. }
  33. public void Add(ConversationReference conversationReference)
  34. {
  35. this.surveyRequests.Enqueue(conversationReference);
  36. }
  37. }
  38. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...