// Both Data Queue and Queue under SynchronizationContext allow handoff of data
// Data Consumer can be parallel Enumerable or Subscribe to Observables
// UI can only singled threaded Async or sync
void BlockingCollectionAsQueue()
{
BlockingCollection<string> ServerData = new BlockingCollection<string>(10000);
ServerData.Add("Data");
ServerData.CompleteAdding();
string data1;
ServerData.TryTake(out data1, TimeSpan.FromMilliseconds(2));
IEnumerable<string> data = ServerData.GetConsumingEnumerable();
foreach (var v in data.AsParallel().AsOrdered().Select(l => Regex.Replace(l, @"\s+", ""))) ;
}
void UIMarshalling()
{
ThreadPool.QueueUserWorkItem((s) =>
{
//do some server side work
// UIControl.Invoke();
//Dispatcher.Invoke();
SendOrPostCallback spcb = new SendOrPostCallback((obj) => { });
// SynchronizationContext =WPF.Dispatcher or WF.Control.Invoke
SynchronizationContext.Current.Send((state) =>
{
//UI.Property="";
}, "");
});
}
http://www.martinpersson.org/wordpress/2012/12/application-launcher/
Sunday, July 6, 2014
Producer Consumer Pattern with HandOff point
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment