15 분마다 "google"을 핑하는 프로그램을 C#으로 만들고 있습니다. ping이 성공적이면 15 분 후에 다시 검사 (ping)됩니다. ping이 성공하지 못하면 ISP의 Dailer를 실행하고 15 분마다 다시 검사합니다.C#에서 타이머를 설정하는 방법은 무엇입니까?
나는 모든 코드를 작성했지만 매 15 분마다 코드를 반복하도록 타이머를 설정할 수는 없습니다. 누군가가 나를 도울 수 있다면, 나는 정말로 감사 할 것입니다.
이것은 코드입니다. 내 전화 걸기가 이미 나는이 프로그램을 실행하면 연결되어있는 경우이 코드가 무엇을
using System;
using System.Windows.Forms;
using System.Net.NetworkInformation;
using System.Net;
using System.Diagnostics;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer.Interval = (4000); //For checking, I have set the interval to 4 sec. It actually needs to be 15 minutes.
timer.Enabled = true;
timer.Start();
Ping ping = new Ping();
PingReply pingStatus = ping.Send(IPAddress.Parse("208.69.34.231"));
if (pingStatus.Status != IPStatus.Success)
{
timer.Tick += new EventHandler(timer1_Tick);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
Process.Start("C:\\WINDOWS\\system32\\rasphone.exe","-d DELTA1");
}
}
}
는 - 그것은 아무것도하지 않는다. 4 초 후에 다시 확인하지 않습니다. 그러나이 프로그램을 실행할 때 전화 걸기가 연결되어 있지 않으면 즉시 걸기를 연결하고 확인하지 않고 4 초마다 전화 걸기를 다시 시도합니다 (Google에 ping).
전에 타이머 기능을 사용 해본 적이 없어서 타이머를 올바르게 설정하지 못했습니다. 누군가가 나를 도울 수 있다면 정말 감사 할 것입니다. 당신이 당신의 타이머의 Tick
핸들러 내부에 핑 코드를 이동해야처럼
감사합니다, Shajee의 A.는
MSDN의 [documentation] (http://msdn.microsoft.com/en-us/library/system.timers.timer (v = vs.71) .aspx)을 확인 했습니까? – Nealon
틱? 진드기가 뭐니? 맞춤 타이머 클래스를 사용하고 있습니까? – Serge
@ Serge 나는''System.Windows.Forms.Timer' (http://msdn.microsoft.com/en-us/library/xdh6857z.aspx)를 사용하여 OP를 가정합니다.이 OP는' System.Timers' 또는 System.Threading입니다. –