저는 C#의 초보자이며 static void Main()
에서 함수 즉 SetTimer()
을 호출하려고합니다. 그러나 아래에 SetTimer(11, 48, 00);
과 SetTimer(11, 35, 40);
으로 오류가 있습니다. 사실, Main()
함수를 사용하면 양식에서 제대로 작동 할 수 있습니다."정적 메인"방법으로 다른 함수를 호출하는 방법은 무엇입니까?
- 공공 무효
- 정적 무효
- 공공 정적 무효
- 개인 정적 무효
- 무효
: 나는 이러한 유형을 사용하는 방법과시기에 대한 혼란스러워 있어요
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
namespace SetTimerAlert
{
public class Program
{
int count = 0;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
//Application.Run(new Form1());
if (rkApp.GetValue("SetTimerAlert") == null)
{
Application.Run(new Form1());
}
else
{
SetTimer(11, 48, 00);
SetTimer(11, 35, 40);
}
}
public void SetTimer(int hh, int mm, int ss)
{
DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, hh, mm, ss);
TimerCallback callback = new TimerCallback(ProcessTimerEvent);
if (DateTime.Now < dt)
{
var timer = new System.Threading.Timer(callback, null,
//other occurrences every 24 hours
dt - DateTime.Now, TimeSpan.FromHours(24));
}
}
public void ProcessTimerEvent(object obj)
{
if (count == 0)
{
//rkApp.SetValue("SetTimerAlert", Application.ExecutablePath.ToString());
MessageBox.Show("Please run programs.");
count++;
}
else
{
MessageBox.Show("Hey! I did not see the program runs. Your computer will be shut down for 15 seconds.");
}
}
}
}
개체를 인스턴스화합니다. 인스턴스 메소드를 호출하십시오. – user2864740