public void GetTextLines(object state, GetTextLinesHandler onGetLineInfoComplete) { lock (_syncRoot) { if (_getTextLineInfo.IsCompleted) { Task.Factory.StartNew(o => { object[] args = o as object[]; GetTextLinesHandler h = args[0] as GetTextLinesHandler; h(args[1], args[2] as string, args[3] as Task <Model.TextLine[]>); }, new object[] { onGetLineInfoComplete, state, _text, _getTextLineInfo }); } else { _onGetLineInfoComplete.Add(new Tuple <object, GetTextLinesHandler>(state, onGetLineInfoComplete)); } } }
private void GetTextLineInfoCompleted(Task <Model.TextLine[]> task) { lock (_syncRoot) { if (task.Id != _getTextLineInfo.Id || task.IsCanceled) { return; } foreach (Tuple <object, GetTextLinesHandler> handler in _onGetLineInfoComplete) { task.ContinueWith((t, o) => { object[] args = o as object[]; Tuple <object, GetTextLinesHandler> h = args[0] as Tuple <object, GetTextLinesHandler>; GetTextLinesHandler onGetLineInfoComplete = h.Item2; onGetLineInfoComplete(h.Item1, args[1] as string, t); }, new object[] { handler, _text }); } _onGetLineInfoComplete.Clear(); } }