Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# AppSettings[“ScheduledTime”]); 如果(DateTime.Now>scheduledTime) { //如果超过预定时间,则设置第二天的计划。 scheduledTime=scheduledTime.AddDays(1); } } if(mode.ToUpper()=“间隔”) { //从AppSettings获取以分钟为单位的间隔。 int intervalMinutes=Convert.ToInt32(ConfigurationManager.AppSettings[“intervalMinutes”]); //通过将间隔添加到当前时间来设置计划时间。 scheduledTime=DateTime.Now.AddMinutes(intervalMinutes); 如果(DateTime.Now>scheduledTime) { //如果超过计划时间,则设置下一个间隔的计划。 scheduledTime=scheduledTime.AddMinutes(intervalMinutes); } } TimeSpan TimeSpan=scheduledTime.Subtract(DateTime.Now); string schedule=string.Format(“{0}天{1}小时{2}分钟{3}秒)”,timeSpan.Days,timeSpan.Hours,timeSpan.Minutes,timeSpan.seconds); 这个.WriteToFile(“计划在“+schedule+”{0}”之后运行的简单服务”); //获取计划时间和当前时间之间的差异(以分钟为单位)。 int dueTime=Convert.ToInt32(timeSpan.total毫秒); //更改计时器的到期时间。 调度更改(dueTime,Timeout.Infinite); } 捕获(例外情况除外) { WriteToFile(“在:{0}”+ex.Message+ex.StackTrace上的简单服务错误); //停止Windows服务。 使用(System.ServiceProcess.ServiceController ServiceController=new System.ServiceProcess.ServiceController(“SparkBirthDayGreeting”)) { serviceController.Stop(); } } } 私有void WriteToFile(字符串文本) { string path=“C:\\ServiceLog.txt”; 使用(StreamWriter=newstreamwriter(路径,true)) { WriteLine(string.Format(text,DateTime.Now.ToString(“dd/MM/yyyy hh:MM:ss tt”)); writer.Close(); } }_C#_Windows Services_Xmpp_Jabberd2 - Fatal编程技术网

C# AppSettings[“ScheduledTime”]); 如果(DateTime.Now>scheduledTime) { //如果超过预定时间,则设置第二天的计划。 scheduledTime=scheduledTime.AddDays(1); } } if(mode.ToUpper()=“间隔”) { //从AppSettings获取以分钟为单位的间隔。 int intervalMinutes=Convert.ToInt32(ConfigurationManager.AppSettings[“intervalMinutes”]); //通过将间隔添加到当前时间来设置计划时间。 scheduledTime=DateTime.Now.AddMinutes(intervalMinutes); 如果(DateTime.Now>scheduledTime) { //如果超过计划时间,则设置下一个间隔的计划。 scheduledTime=scheduledTime.AddMinutes(intervalMinutes); } } TimeSpan TimeSpan=scheduledTime.Subtract(DateTime.Now); string schedule=string.Format(“{0}天{1}小时{2}分钟{3}秒)”,timeSpan.Days,timeSpan.Hours,timeSpan.Minutes,timeSpan.seconds); 这个.WriteToFile(“计划在“+schedule+”{0}”之后运行的简单服务”); //获取计划时间和当前时间之间的差异(以分钟为单位)。 int dueTime=Convert.ToInt32(timeSpan.total毫秒); //更改计时器的到期时间。 调度更改(dueTime,Timeout.Infinite); } 捕获(例外情况除外) { WriteToFile(“在:{0}”+ex.Message+ex.StackTrace上的简单服务错误); //停止Windows服务。 使用(System.ServiceProcess.ServiceController ServiceController=new System.ServiceProcess.ServiceController(“SparkBirthDayGreeting”)) { serviceController.Stop(); } } } 私有void WriteToFile(字符串文本) { string path=“C:\\ServiceLog.txt”; 使用(StreamWriter=newstreamwriter(路径,true)) { WriteLine(string.Format(text,DateTime.Now.ToString(“dd/MM/yyyy hh:MM:ss tt”)); writer.Close(); } }

C# AppSettings[“ScheduledTime”]); 如果(DateTime.Now>scheduledTime) { //如果超过预定时间,则设置第二天的计划。 scheduledTime=scheduledTime.AddDays(1); } } if(mode.ToUpper()=“间隔”) { //从AppSettings获取以分钟为单位的间隔。 int intervalMinutes=Convert.ToInt32(ConfigurationManager.AppSettings[“intervalMinutes”]); //通过将间隔添加到当前时间来设置计划时间。 scheduledTime=DateTime.Now.AddMinutes(intervalMinutes); 如果(DateTime.Now>scheduledTime) { //如果超过计划时间,则设置下一个间隔的计划。 scheduledTime=scheduledTime.AddMinutes(intervalMinutes); } } TimeSpan TimeSpan=scheduledTime.Subtract(DateTime.Now); string schedule=string.Format(“{0}天{1}小时{2}分钟{3}秒)”,timeSpan.Days,timeSpan.Hours,timeSpan.Minutes,timeSpan.seconds); 这个.WriteToFile(“计划在“+schedule+”{0}”之后运行的简单服务”); //获取计划时间和当前时间之间的差异(以分钟为单位)。 int dueTime=Convert.ToInt32(timeSpan.total毫秒); //更改计时器的到期时间。 调度更改(dueTime,Timeout.Infinite); } 捕获(例外情况除外) { WriteToFile(“在:{0}”+ex.Message+ex.StackTrace上的简单服务错误); //停止Windows服务。 使用(System.ServiceProcess.ServiceController ServiceController=new System.ServiceProcess.ServiceController(“SparkBirthDayGreeting”)) { serviceController.Stop(); } } } 私有void WriteToFile(字符串文本) { string path=“C:\\ServiceLog.txt”; 使用(StreamWriter=newstreamwriter(路径,true)) { WriteLine(string.Format(text,DateTime.Now.ToString(“dd/MM/yyyy hh:MM:ss tt”)); writer.Close(); } },c#,windows-services,xmpp,jabberd2,C#,Windows Services,Xmpp,Jabberd2,我希望有人能帮我。我被卡住了:( 谢谢。问题在于JabberClient的事件是在j_OnAuthenticate中处理的,计时器的事件是用它处理的: Schedular = new Timer(new TimerCallback(j_OnAuthenticate)); ... JabberClient j = new JabberClient(); j.OnAuthenticate += new bedrock.ObjectHandler(j_OnAuthenticate); 在j_OnAu

我希望有人能帮我。我被卡住了:(
谢谢。

问题在于
JabberClient
的事件是在
j_OnAuthenticate
中处理的,计时器的事件是用它处理的:

Schedular = new Timer(new TimerCallback(j_OnAuthenticate));
...
JabberClient j = new JabberClient();
j.OnAuthenticate += new bedrock.ObjectHandler(j_OnAuthenticate);
j_OnAuthenticate
中,您要做的第一件事是将
发送方
转换为
JabberClient

private void j_OnAuthenticate(object sender)
{

   try
   {
       JabberClient j = (JabberClient)sender;
       ...
   }
   catch (Exception ex)
   {
       WriteToFile("Simple Service Error on: {0} " + ex.Message + ex.StackTrace);

       //Stop the Windows Service.
       using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController("SparkBirthDayGreeting"))
       {
            serviceController.Stop();
       }
   }
catch
块处理并记录异常

根据发件人的不同,您必须更改代码才能执行不同的操作,例如:

if(sender is JabberClient)
{
    //do something
}
else if(sender is Timer)
{
    //do something else
}

或者给计时器一个不同的回调函数

您已经放入了所有对诊断问题无效的代码,并删除了唯一相关的部分…(
j_OnAuthenticate
是唯一相关的部分,顺便说一句)异常的堆栈跟踪清楚地指出了错误发生的位置。不幸的是,您从问题中完全删除了该部分代码。顺便说一句,错误消息非常自我解释。抱歉,我将编辑它“//这是向用户发送消息的部分,我删除了这里的代码,因为它太长了,但我已经在winforms中测试了它,它正在发送”(我强调)-这是什么意思“您在winforms中测试了它?”“?@Fildor我有一个winform应用程序,用上面的代码测试发送消息是否有效,ScheduleService方法除外。我会试试这个。谢谢
if(sender is JabberClient)
{
    //do something
}
else if(sender is Timer)
{
    //do something else
}