public ThreadTimer(Fun0 <Unit> cb, int ms) { entry = Primitive.GetEventloopEntry(); if (ms <= 0) { timer = null; entry.Post(() => { cb.Apply(); }); } else { timer = new Timer((object state0) => { if (entry != null) { entry.Post(() => { cb.Apply(); }); } }, null, ms, Timeout.Infinite); } }
public _DownloadText(string uri, double timeout, Fun2 <Exception, string, Unit> cb) { entry = Primitive.GetEventloopEntry(); webClient = new System.Net.WebClient(); try { webClient.DownloadStringCompleted += (object sender, System.Net.DownloadStringCompletedEventArgs e) => { if (entry != null) { entry.Post(() => cb.Call(e.Error, (e.Error != null ? "" : e.Result))); entry = null; } Dispose(); }; webClient.DownloadStringAsync(new Uri(uri)); } catch (Exception exn) { Dispose(); throw exn; } }