Exemplo n.º 1
0
            private void ReadCompletedCallback(IAsyncResult ar)
            {
                ReadWorkerDelegate worker = (ReadWorkerDelegate)((AsyncResult)ar).AsyncDelegate;

                worker.EndInvoke(ar);
                lock (myLock)
                {
                    readIsRunning = false;
                }
            }
Exemplo n.º 2
0
            public void ReadAsync(StreamReader stream)
            {
                ReadWorkerDelegate worker            = new ReadWorkerDelegate(ReadWorker);
                AsyncCallback      completedCallback = new AsyncCallback(ReadCompletedCallback);

                lock (myLock)
                {
                    if (readIsRunning)
                    {
                        throw new InvalidOperationException("The control is currently busy.");
                    }

                    AsyncOperation async = AsyncOperationManager.CreateOperation(null);
                    worker.BeginInvoke(stream, completedCallback, async);
                    readIsRunning = true;
                }
            }