备用Application.Run Winform的Program.cs中的文件 [英] Alternate Application.Run Winform In Program.cs File

查看:227
本文介绍了备用Application.Run Winform的Program.cs中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Winform中的一个项目,我想运行由另一种形式的应用程序。在文件中的Program.cs有:

I have a project of two Winform and I want to run the application by alternate form. In program.cs file there is:

Application.Run(new Form1());

这意味着在Form1将执行为主要形式或应用程序的启动方式。
是否有可能被一些时间限制或限制天编程改变呢?
我的意思是两天后它会执行窗体2作为启动窗体。
象下面这样:

That means the Form1 will execute as main form or startup form of application. Is it possible to change it programmatically by some time limit or days limit? I mean after two days it will execute Form2 as startup form. Like below:

Application.Run(new Form2());



这可能吗?

Is it possible?

推荐答案

当然,这是没有问题的:

Sure, that's no problem:

var startDate = ReadStartDateFromFile();
if(DateTime.Now.Subtract(startDate).TotalDays < 2 || startDate == new DateTime())
    Application.Run(new Form1());
else
    Application.Run(new Form2());



该方法 ReadStartDateFromFile 读取的日期你的程序的第一次启动。如果之前从未开始,它返回新的DateTime()。结果
。如果你想用这样的一种方式来实现共享机制,考虑使用混淆器,否则,很容易被破解。此外,您应该加密的文件,你写的开始日期。此外,考虑设置,创建一个伪日期该文件。如果有人简单地删除文件,你应该考虑一个安全漏洞,并直接显示窗体2

The method ReadStartDateFromFile reads the date of the first start of your program. If it has never been started before, it returns new DateTime().
If you want to use this as a way to implement a shareware mechanism, consider using an obfuscator, otherwise, it is very easy to crack. Additionally, you should encrypt the file, you write the start date to. Additionally, consider a setup, that creates that file with a dummy date. If someone simply deletes the file, you should consider that a security breach and directly show Form2.

感谢马克在评论大讨论!

Thanks to Mark for the great discussion in the comments!

这篇关于备用Application.Run Winform的Program.cs中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆