using System;
using System.Collections.Generic;
using System.Text;
using System.Timers;
using System.Collections;
using System.Runtime.InteropServices;
using System.IO;
using System.Diagnostics;
namespace BeepTime
{
class Program
{
[DllImport("Kernel32.dll ")]
public static extern int Beep(uint dwFreq, uint dwDuration);
private static void TimedEvent(object source, ElapsedEventArgs e)
{
Beep(1000, 1000);
}
static void Main(string[] args)
{
int i = 0;
StreamReader sr = new StreamReader("deploy.txt");
string strling = sr.ReadLine();
while (strling != null)
{
if (strling.Contains("Beep"))
{
string[] beep = strling.Split('|');
i = int.Parse(beep[3].ToString()); }
strling = sr.ReadLine();
}
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(TimedEvent);
// Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = i;
aTimer.Enabled = true;
Console.ReadLine();
}
}
}
上面是让主板报警的信息:其中读取一个文本文件:获取时间报警 部分文本内容 Beep|1000|1000|20000 20秒报警一次
static void Main(string[] args)
{ Process[] processes;
processes = System.Diagnostics.Process.GetProcesses();//获取系统进程
Process process;
string ProcessName = "";
for (int i = 0; i < processes.Length - 1; i++)
{
process = processes[i];
if (process.ProcessName == "BeepTime")//获取student进程的路径
{
ProcessName = process.ProcessName;
}
}
if (ProcessName == "")
{
Process proc = new Process();
proc.StartInfo.UseShellExecute = false;
//proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.RedirectStandardOutput = true; //proc.StartInfo.RedirectStandardError = true; proc.StartInfo.CreateNoWindow = true;
//proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.FileName = "BeepTime.exe";
proc.StartInfo.Arguments = "";
proc.Start();
}
}使用一个进程调用BeetTime.exe 让它进行报警: 一点问题都没有,可以设置时间: 比如我在deploy.txt修改时间,那么它会根据我修改的时间 进行报警!提问:下面是一个服务:我把程序改成服务之后!服务就按照10秒钟叫一次,设置时间就无效了
请问各位大侠:这个问题有人遇到过吗?还是我的程序有问题:
下面是服务代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Timers;
using System.Collections;namespace TEST
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
} protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
System.Timers.Timer aTimer = new System.Timers.Timer(); // Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); // Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 60000;
aTimer.Enabled = true; // Keep the timer alive until the end of Main.
GC.KeepAlive(aTimer);
//DataReceive.Listener();
} protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service. timer1.Enabled = false;
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Process[] processes;
processes = System.Diagnostics.Process.GetProcesses();//获取系统进程
Process process;
string ProcessName = "";
for (int i = 0; i < processes.Length - 1; i++)
{
process = processes[i];
if (process.ProcessName == "BeepTime")//获取student进程的路径
{
ProcessName = process.ProcessName;
}
}
if (ProcessName == "")
{
Process proc = new Process();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.FileName = "BeepTime.exe";
proc.StartInfo.Arguments = "";
proc.Start(); }
else
{ } }
}
}
using System.Collections.Generic;
using System.Text;
using System.Timers;
using System.Collections;
using System.Runtime.InteropServices;
using System.IO;
using System.Diagnostics;
namespace BeepTime
{
class Program
{
[DllImport("Kernel32.dll ")]
public static extern int Beep(uint dwFreq, uint dwDuration);
private static void TimedEvent(object source, ElapsedEventArgs e)
{
Beep(1000, 1000);
}
static void Main(string[] args)
{
int i = 0;
StreamReader sr = new StreamReader("deploy.txt");
string strling = sr.ReadLine();
while (strling != null)
{
if (strling.Contains("Beep"))
{
string[] beep = strling.Split('|');
i = int.Parse(beep[3].ToString()); }
strling = sr.ReadLine();
}
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(TimedEvent);
// Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = i;
aTimer.Enabled = true;
Console.ReadLine();
}
}
}
上面是让主板报警的信息:其中读取一个文本文件:获取时间报警 部分文本内容 Beep|1000|1000|20000 20秒报警一次
static void Main(string[] args)
{ Process[] processes;
processes = System.Diagnostics.Process.GetProcesses();//获取系统进程
Process process;
string ProcessName = "";
for (int i = 0; i < processes.Length - 1; i++)
{
process = processes[i];
if (process.ProcessName == "BeepTime")//获取student进程的路径
{
ProcessName = process.ProcessName;
}
}
if (ProcessName == "")
{
Process proc = new Process();
proc.StartInfo.UseShellExecute = false;
//proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.RedirectStandardOutput = true; //proc.StartInfo.RedirectStandardError = true; proc.StartInfo.CreateNoWindow = true;
//proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.FileName = "BeepTime.exe";
proc.StartInfo.Arguments = "";
proc.Start();
}
}使用一个进程调用BeetTime.exe 让它进行报警: 一点问题都没有,可以设置时间: 比如我在deploy.txt修改时间,那么它会根据我修改的时间 进行报警!提问:下面是一个服务:我把程序改成服务之后!服务就按照10秒钟叫一次,设置时间就无效了
请问各位大侠:这个问题有人遇到过吗?还是我的程序有问题:
下面是服务代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Timers;
using System.Collections;namespace TEST
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
} protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
System.Timers.Timer aTimer = new System.Timers.Timer(); // Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); // Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 60000;
aTimer.Enabled = true; // Keep the timer alive until the end of Main.
GC.KeepAlive(aTimer);
//DataReceive.Listener();
} protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service. timer1.Enabled = false;
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Process[] processes;
processes = System.Diagnostics.Process.GetProcesses();//获取系统进程
Process process;
string ProcessName = "";
for (int i = 0; i < processes.Length - 1; i++)
{
process = processes[i];
if (process.ProcessName == "BeepTime")//获取student进程的路径
{
ProcessName = process.ProcessName;
}
}
if (ProcessName == "")
{
Process proc = new Process();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.FileName = "BeepTime.exe";
proc.StartInfo.Arguments = "";
proc.Start(); }
else
{ } }
}
}
谢谢你的回答!