Example #1
0
        ///<summary>
        /// Called when an asynchronous Find Next/Previous operation finishes.
        ///</summary>
        void FindAsyncCallback(IAsyncResult ar)
        {
            GenericFindOperation state = (GenericFindOperation)ar.AsyncState;

            ThreadedAsyncOperation.OperationResult result = state.Result;
            Range match = state.Match;

            DataView dv = null;

            // find DataView that owns bb
            foreach (DataViewDisplay dvtemp in dataBook.Children)
            {
                if (dvtemp.View.Buffer == strategy.Buffer)
                {
                    dv = dvtemp.View;
                    break;
                }
            }

            // decide what to do based on the result of the find operation
            switch (result)
            {
            case ThreadedAsyncOperation.OperationResult.Finished:
                if (match != null)
                {
                    lastFound = match;
                    dv.SetSelection(match.Start, match.End);                    //System.Console.WriteLine("Found at {0}-{1}", r.Start, r.End);
                    dv.MoveCursor(match.End + 1, 0);
                    dv.Display.MakeOffsetVisible(match.Start, DataViewDisplay.ShowType.Closest);
                }
                else
                {
                    lastFound.Clear();
                }
                break;

            case ThreadedAsyncOperation.OperationResult.Cancelled:
                dv.MoveCursor(strategy.Position, 0);
                dv.Display.MakeOffsetVisible(strategy.Position, DataViewDisplay.ShowType.Closest);
                break;

            case ThreadedAsyncOperation.OperationResult.CaughtException:
                break;

            default:
                break;
            }

            inUse = false;

            // if user provided a callback, call it now
            if (userFindAsyncCallback != null)
            {
                userFindAsyncCallback(ar);
            }

            // notify that the find operation has finished
            findFinishedEvent.Set();
        }
Example #2
0
        ///<summary>
        /// Handles operations that will surely produce on result (eg when
        /// no DataView exists).
        ///</summary>
        IAsyncResult HandleProblematicOp(GenericFindOperation op, AsyncCallback ac)
        {
            op.Result = GenericFindOperation.OperationResult.Finished;

            findFinishedEvent.Reset();

            IAsyncResult iar = new ThreadedAsyncResult(op, findFinishedEvent, true);

            if (ac != null)
            {
                ac(iar);
            }

            findFinishedEvent.Set();
            return(iar);
        }