Skip to content

Instantly share code, notes, and snippets.

@NoahRic
Created October 22, 2009 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoahRic/216080 to your computer and use it in GitHub Desktop.
Save NoahRic/216080 to your computer and use it in GitHub Desktop.
// 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