简体   繁体   English

仅在经过一段时间后才执行某些操作

[英]Execute something only when some time has been elapsed

This is kinda hard to explain for me but look: 这对我来说很难解释,但请注意:

I made a MMORPG server launcher wich has a start button, whe you click it a little window pops up and asks you to vote for the server and then you can click start again to launch the game(there is a 10 sec countdown before you can actually start the game) 我制作了一个MMORPG服务器启动器,其中有一个启动按钮,如果您单击它,会弹出一个小窗口并要求您为服务器投票,然后您可以再次单击启动来启动游戏(倒计时10秒钟,然后您可以真正开始游戏)

The only thing is that the vote website only accepts a vote from an user each 12 hours(IP and cookie based) and after someone has voted once, it is kinda annoying to have that little window pop up and wait each time you want to start the game. 唯一的事情是,投票网站每12个小时(基于IP和Cookie)仅接受用户的一次投票,并且在某人投票一次之后,弹出小窗口并在每次您想开始时都等待它是很烦人的游戏。

My idea is: When someone clicks to open the vote window, his system's date and exact hour aer written into a file. 我的想法是:当某人单击以打开投票窗口时,其系统的日期和确切的小时数就会写入文件中。

After that, each time you click start the launchers reads that date and time and calculates if 12 hours have been elapsed since you last voted, if yes, it will ask you again to vote and IF NOT, it will just skip that part and directly start the game. 之后,每次单击开始时,启动器都会读取该日期和时间,并计算自上次投票以来是否经过了12个小时,如果是,它将再次询问您是否投票,如果不投票,它将直接跳过该部分开始游戏。

I'm not very experienced and I don't know where to start and how to make this work, your help is highly appreciated. 我经验不足,也不知道从哪里开始以及如何进行这项工作,我们非常感谢您的帮助。

Thank you! 谢谢!

Here's my event if it can help. 如果可以的话,这是我的活动。

    private void btnStart_Click(object sender, EventArgs e)
    {
        var voteForm = new VoteWindow();
        voteForm.Show();
        voteForm.BringToFront();
        this.Enabled = false;
    }

And here is my code for actually starting the game. 这是我实际开始游戏的代码。

    private void btnStart2_Click(object sender, EventArgs e)
    {
        string error1 = "Deleted because it was too long...";
        string title1 = "Deleted because it was too long...";

        if (File.Exists("engine.exe"))
        {
            Process.Start("engine.exe", "/load /config debug");
            Application.Exit();
        }
        else
        {
            MessageBox.Show(error1, title1, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

Just use Properties.Settings . 只需使用Properties.Settings You can create a new setting by going to your Solution Explorer then expand Properties and open up Settings.Settings . 您可以通过转到Solution Explorer来创建新设置,然后展开“ Properties并打开Settings.Settings On this page you can create a new System.DateTime object. 在此页面上,您可以创建一个新的System.DateTime对象。 Then you would do something like this. 然后,您将执行以下操作。

private void btnStart_Click(object sender, EventArgs e)
{
    TimeSpan ts = DateTime.Now - Properties.Settings.Default.MySetting;

    if (ts.TotalHours > 12)
    {
        Properties.Settings.Default.MySetting = DateTime.Now;
        Properties.Settings.Default.Save();

        var voteForm = new VoteWindow();
        voteForm.Show();
        voteForm.BringToFront();
        this.Enabled = false;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM