Toasts – Blame information for rev 17

Subversion Repositories:
Rev:
Rev Author Line No. Line
16 office 1 using System;
2 using System.Threading;
3 using System.Threading.Tasks;
4 using System.Threading.Tasks.Dataflow;
5 using System.Windows.Forms;
6  
7 namespace Toasts
8 {
9 public class Toasts : IDisposable
10 {
11 private readonly CancellationToken _cancellationToken;
12 private readonly BufferBlock<ToastForm> _toastFormBufferBlock;
13 private IDisposable _toastFromActionBlockLink;
14  
15 private Toasts()
16 {
17  
18 }
19  
20 public Toasts(CancellationToken cancellationToken) : this()
21 {
22 _cancellationToken = cancellationToken;
23  
24 _toastFormBufferBlock = new BufferBlock<ToastForm>(new DataflowBlockOptions { EnsureOrdered = true, CancellationToken = _cancellationToken});
25 var toastFormActionBlock = new ActionBlock<ToastForm>(DisplayForm, new ExecutionDataflowBlockOptions { EnsureOrdered = true, CancellationToken = _cancellationToken });
26  
27 _toastFromActionBlockLink = _toastFormBufferBlock.LinkTo(toastFormActionBlock);
28 }
29  
30 public void Dispose()
31 {
32 if (_toastFromActionBlockLink != null)
33 {
34 _toastFromActionBlockLink?.Dispose();
35 _toastFromActionBlockLink = null;
36 }
37 }
38  
39 private void DisplayForm(ToastForm toastForm)
40 {
41 Task.Factory.StartNew(() =>
42 {
43 Application.Run(toastForm);
44 }, _cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
45 }
46  
17 office 47 public async Task Queue(ToastForm toastForm)
16 office 48 {
49 await _toastFormBufferBlock.SendAsync(toastForm, _cancellationToken);
50 }
51 }
52 }