使用Rx,我有一个代码:
class Program
{
static void Main(string[] args)
{
var test = new TestClass();
var observable = Observable
.FromEventPattern<EventArgs>(e => test.TestEvent += e, e => test.TestEvent -= e);
//.SubscribeOn ...
//.Subscribe ...
test.InvokeFromOtherThread();
var result = observable.Wait();
}
}
class TestClass
{
public event EventHandler<EventArgs> TestEvent;
public void InvokeFromOtherThread()
{
var task = new Task(() =>
{
Thread.Sleep(5000);
TestEvent.Invoke(this, new EventArgs());
});
task.Start();
}
}
我想等待在其他线程中传递的EventArgs实例。我应该如何使用SubscrinbeOn?如果我使用SubscribeOn(Scheduler.Current)没有任何反应。