如何设置每天一次的活动 [英] how to set an event to be take place daily once

查看:91
本文介绍了如何设置每天一次的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置一个动作(发送消息事件)每天一次。我在主窗体中编写了发送消息的代码。因此,当用户打开应用程序时,每次都会发送消息。但我需要它只在一天内发生一次,因此用户可以每次登录,并且只发送一次消息。



如果可能,请提供解决方案和代码谢谢提前。



我尝试了以下代码,但它无法正常工作

Hi, I want to set an action (sending message event) to take place daily once. I wrote the code for sending message in the main Form. So when user opens the application, every time the message will be sent. But I need it to happen only once in a day so the user can login everytime and message is sent only once.

Please provide me the solution and code if possible thanks in advance.

I tried following code but it doesnt work properly

try
{
    // here i try to retrieve date =date.today  from sql table;


                con.Open();
                cmd.CommandText = "select Login_Date from LoginObserver where        Login_Date =" + System.DateTime.Today;
                cmd.ExecuteNonQuery();
                con.Close();
}
// if error enter into the catch block
catch
{

/* this is my code for sending ..but i have not put entire code
   /*code for sending message*/
    sm.sendSMS("number", messagetext);
    
    insert into table where date = datetime.now;
                      con.Open();
                      cmd.CommandText = "Insert Into LoginObserver values('" + 1 + "','" + System.DateTime.Today + "')";
                      cmd.ExecuteScalar();
                      con.Close();

}

但上面的代码不起作用。控制流程没有进入捕获区。



请提供解决方案和代码。



谢谢提前

But the above code not working. Control flow is not entering the catch block.

Please provide me a solution and code.

Thanks in advance

推荐答案

您可以在注册表中为本地计算机设置此项内容。当状态是用户首次登录当前日期时,在注册表中设置值。如果您为此编码,请告诉我
You can set this things in registry for local machine. Set Value in registry when status is the user login on first time on current date. If you code for this let me know


这篇关于如何设置每天一次的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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