Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

refactor to windowing #1

Closed
wants to merge 3 commits into from

1 participant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 7, 2014
  1. @MikeBild

    refactor to windowing

    MikeBild authored
  2. @MikeBild

    Revert "refactor to windowing"

    MikeBild authored
    This reverts commit 4c8078f.
  3. @MikeBild

    remove+add label

    MikeBild authored
This page is out of date. Refresh to see the latest.
Showing with 42 additions and 37 deletions.
  1. +42 −37 RxTimeout/Form1.cs
View
79 RxTimeout/Form1.cs
@@ -3,77 +3,81 @@
using System.Drawing;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
+using System.Threading;
using System.Windows.Forms;
using Minimod.RxMessageBroker;
namespace RxTimeout
{
+
public partial class Form1 : Form
{
- int _offset;
+ int _offset;
+ private Label _label;
public Form1()
{
- InitializeComponent();
+ InitializeComponent();
+
+ RxMessageBrokerMinimod.Default.Register<Start>(Start, TaskPoolScheduler.Default);
+
+ var displayMessageStream = Observable.Empty<Message>();
+ displayMessageStream = RxMessageBrokerMinimod.Default.Stream
+ .OfType<Message>()
+ .ObserveOn(new ControlScheduler(this))
+ .Do(_ =>
+ {
+ if (_label == null) return;
+ Controls.Remove(_label);
+ _label.Dispose();
+ })
+ .Do(CreateAndDisplayLabel)
+ .Timeout(TimeSpan.FromSeconds(5))
+ .ObserveOn(new ControlScheduler(this))
+ .Catch((Exception error) =>
+ {
+ Controls.Remove(_label);
+ _label.Dispose();
+ return displayMessageStream;
+ });
+ displayMessageStream.Subscribe();
+
+
- RxMessageBrokerMinimod.Default.Register<Message>(Message, new ControlScheduler(this));
- RxMessageBrokerMinimod.Default.Register<Start>(Start, TaskPoolScheduler.Default);
}
void Start(Start obj)
{
RxMessageBrokerMinimod.Default.Send(new Message("1"));
- // put Thread.Sleep(20) here and it works...
RxMessageBrokerMinimod.Default.Send(new Message("2"));
RxMessageBrokerMinimod.Default.Send(new Message("3"));
}
- void Message(Message message)
+ void CreateAndDisplayLabel(Message message)
{
Debug.WriteLine(DateTimeOffset.Now.Ticks + " > " + message.Value);
- var label = CreateLabel();
+ _label = CreateLabel();
- label.Text = message.Value;
+ _label.Text = message.Value;
- label.Size = label.GetPreferredSize(Size);
- if (label.Width < ClientRectangle.Width)
+ _label.Size = _label.GetPreferredSize(Size);
+ if (_label.Width < ClientRectangle.Width)
{
- label.Width += 15;
+ _label.Width += 15;
}
- label.Location = new Point(1, ClientRectangle.Height - label.Height - 1 - _offset);
+ _label.Location = new Point(1, ClientRectangle.Height - _label.Height - 1 - _offset);
_offset += 15;
- label.Visible = true;
- Controls.Add(label);
- Controls.SetChildIndex(label, 0);
+ _label.Visible = true;
+ Controls.Add(_label);
+ Controls.SetChildIndex(_label, 0);
- RemoveOnTimeoutOrNextMessage(label);
+ //RemoveOnTimeoutOrNextMessage(label);
Debug.WriteLine(DateTimeOffset.Now.Ticks + " < " + message.Value);
}
- void RemoveOnTimeoutOrNextMessage(Control control)
- {
- const long ItDoesNotMatter = 42L;
-
- var timeout = Observable.Timer(TimeSpan.FromSeconds(5));
- var nextMessage = RxMessageBrokerMinimod.Default.Stream
- .OfType<Message>()
- .Select(_ => ItDoesNotMatter)
- .FirstAsync();
-
- nextMessage
- .Amb(timeout)
- .ObserveOn(this)
- .Do(_ =>
- {
- Controls.Remove(control);
- control.Dispose();
- })
- .Subscribe();
- }
-
void button1_Click(object sender, EventArgs e)
{
RxMessageBrokerMinimod.Default.Send(new Start());
@@ -105,5 +109,6 @@ public Message(string value)
}
public string Value { get; set; }
+ public Control Label { get; set; }
}
}
Something went wrong with that request. Please try again.