[英]Run main form again from Main() with compact framework
I'm developing application for devices that use Compact Framework of C#. 我正在为使用C#紧凑框架的设备开发应用程序。 I need to restart my application or run Application.run with main form from Main method again so that it can be updated. 我需要重新启动我的应用程序,或者再次从Main方法中以主窗体运行Application.run,以便可以对其进行更新。 I can't use Application.Restart() or just Application.Run() as both aren't available in compact framework. 我不能使用Application.Restart()或仅使用Application.Run(),因为两者在紧凑框架中均不可用。 I have tried to use: 我尝试使用:
[DllImport("coredll.dll")]
private static extern bool CeRunAppAtTime(string pwszAppName, DateTime lpTime);
var time = DateTime.Now.AddSeconds(15);
CeRunAppAtTime(fullAppName, time);
but this isn't working. 但这不起作用。 Also tried: 还尝试了:
rocessStartInfo Info = new ProcessStartInfo();
Info.Arguments = "/C ping 127.0.0.1 -n 2 && \"" + fullAppName + "\"";
Info.FileName = "cmd.exe";
Process.Start(Info);
Application.Exit();
but this didn't also work and gave Win32Error. 但这还行不通,并给Win32Error。
Has anyone got any other idea to try or am I doing something wrong with mentioned solutions? 有人有其他想法要尝试吗,或者我在提到的解决方案上做错了什么? Is there a way to execute Application.Run(MyForm) again after Myform.Close() has been run? 在Myform.Close()运行之后,是否可以再次执行Application.Run(MyForm)?
Device I use runs on Windows Embedded Handheld 6.5 Professional CE OS 5.2.29094 我使用的设备在Windows Embedded Handheld 6.5 Professional CE OS 5.2.29094上运行
CeRunAppAtTime
takes in a SYSTEMTIME
structure, not a managed DateTime, so your first call is definitely going to fail. CeRunAppAtTime
采用SYSTEMTIME
结构,而不是托管的DateTime,因此您的第一个调用肯定会失败。
The second looks like you're expecting the CE console to be pretty robust. 第二个看起来像您期望CE控制台非常强大。 Is this a vanilla CE device? 这是香草CE设备吗? If so, the call probably won't work but why not just call to launch your app? 如果是这样,则该呼叫可能无法正常工作,但为什么不直接致电以启动您的应用程序呢? If it's Windows Mobile, where the OS would prevent a second instance from running, then cmd.exe
doesn't even exist (nor does ping
) so that would be a failure point. 如果是Windows Mobile,操作系统会阻止第二个实例运行,则cmd.exe
甚至不存在( ping
也不存在),因此这将是一个故障点。
Your first path is the route I'd go. 您的第一条路是我要走的路。 Just fix it so the P/Invoke takes in a long and pass it a SystemTime value instead of a managed DateTime
. 只需对其进行修复,以使P / Invoke花费很长时间,然后将其传递给SystemTime值而不是托管的DateTime
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.