I am trying to paste current time in any windows using C#. So I defined a global hotkey in C# and when I press the hotkey in any windows, the current time is pasted there.
The issue is that it works perfectly with Notepad, but in Notepad++ it pastes the current time just once and then after that it pastes some strange character which is shown by SYN in Notepad++. I added a thread.sleep(500); before paste command and it works in every windows.
So the question is that why without delay it works in Notepad and not in Notepad++? and how I can get rid of the sleep delay in order to make it works in every windows?
Thanks in advance.
here is my code:
public static void PasteDT()
{
ClipPut(DateTime.Now.ToString("HHmmss"));
//Thread.Sleep(500); //<< without this line it works just once in Notepad++
SendKeys.SendWait("^v");
}
public static void ClipPut(string ClipboardText)
{
Thread clipboardThread = new Thread(() => Clipboard.SetText(ClipboardText));
clipboardThread.SetApartmentState(ApartmentState.STA);
clipboardThread.IsBackground = false;
clipboardThread.Start();
clipboardThread.Join();
}