Created
October 22, 2009 16:51
-
-
Save NoahRic/216080 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// On a background thread, perform our typing work. | |
ThreadPool.QueueUserWorkItem((state) => | |
{ | |
Random random = new Random(); | |
for (int i = 0; i < _textToType.Length; i++) | |
{ | |
// Dispatch back to the UI thread to make the edit on the buffer | |
_dispatcher.Invoke(new Action(() => | |
{ | |
ITextSnapshot snapshot = _insertionPoint.TextBuffer.CurrentSnapshot; | |
SnapshotPoint insertionPoint = _insertionPoint.GetPoint(snapshot); | |
if (i == 0) | |
CaptureInsertionSpan(insertionPoint); | |
snapshot.TextBuffer.Insert(insertionPoint, _textToType.Substring(i, 1)); | |
}), DispatcherPriority.Normal); | |
// Between each typing action, sleep for a little while | |
Thread.Sleep(50 + random.Next(200)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment