Silverlight 4 - send text to Notepad

╄→гoц情女王★ 提交于 2019-12-10 10:44:45

问题


I try this tutorial

http://elegantcode.com/2010/02/20/silverlight-4-com-interop-and-the-cool-stuff-you-can-do-with-it/

I need open Notepad and send text into. I use this code:

using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
    {
        shell.Run(@"C:\windows\notepad.exe"); //you can open anything

        shell.SendKeys(txtTextToSend.Text);
    }

When I start aplication the notepad has appeared but there is no text in it.

What do I wrong. My system is W7 64bit. Thanks


回答1:


The problem is that Run is a non-blocking operation that will return as soon as it has spun up the process. The UI for notepad probably hasn't appeared and put the focus into its input area by the time your code is calling SendKeys.

Try introducing a Thread.Sleep for a couple of seconds to prove whether this is true.



来源:https://stackoverflow.com/questions/4985500/silverlight-4-send-text-to-notepad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!