Hi, <br/>
Ive been trying to get this to work for quite some time now. This is <br/> my goal: When my application starts, it has to call a web service <br/> immediately, and setup a timer to call the same method every few <br/> minutes. This is my code:
<pre lang="x-c# Class MyApplication
{
...
private System.Timers.Timer syncTimer;
Public void Startup()
{
Logger.Debug("Syncing at startup + setting up timer");
Core.Sync();
syncTimer = new System.Timers.Timer();
syncTimer.Elapsed += new System.Timers.ElapsedEventHandler(syncTimer_Elapsed);
syncTimer.Interval = 60000; //Perform sync every minute
syncTimer.AutoReset = true;
syncTimer.Start();
}
void syncTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Core.Sync();
}
}
Public static class Core
{
public static void Sync()
{
// Following line instanciates web service and adds the correct URL from settings
ionSyncPlugin.ionSyncWS.Webservice ionPmWS = Library.InitWebservice();
ionPmWS.GetUserProjectsCompleted += new ionSyncPlugin.ionSyncWS.GetUserProjectsCompletedEventHandler(getProjectsCompleted);
ionPmWS.GetUserProjectsAsync(settings.Login,Library.GetMD5(settings.Password));
}
private static void getProjectsCompleted(object sender, ionSyncPlugin.ionSyncWS.GetUserProjectsCompletedEventArgs e)
{
// Do some stuff with the result
}
}
[/code]
<br/>
<div class=qt style=" <br/>
When the program starts, the first Sync (being started from Startup()) <br/> works fine. But whenever the timer fires the elapsed event, the <br/> program performs a request, but the getProjectsCompleted eventhandler <br/> is never started. <br/>
According to my findings, the request reaches the web service, and the <br/> method (getProjects) is being processed on server side successfully. <br/> Ive also tried testing the application with the web service running <br/> locally in Visual Studio. The result was the same.
Ive tried setting up the timer object inside the Core class instead <br/> of the application class, but the result was just the same.
Can anyone explain to me why this is happening ?
Thanks in advance!
Kind regards, <br/> Mathew
View the full article
Ive been trying to get this to work for quite some time now. This is <br/> my goal: When my application starts, it has to call a web service <br/> immediately, and setup a timer to call the same method every few <br/> minutes. This is my code:
<pre lang="x-c# Class MyApplication
{
...
private System.Timers.Timer syncTimer;
Public void Startup()
{
Logger.Debug("Syncing at startup + setting up timer");
Core.Sync();
syncTimer = new System.Timers.Timer();
syncTimer.Elapsed += new System.Timers.ElapsedEventHandler(syncTimer_Elapsed);
syncTimer.Interval = 60000; //Perform sync every minute
syncTimer.AutoReset = true;
syncTimer.Start();
}
void syncTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Core.Sync();
}
}
Public static class Core
{
public static void Sync()
{
// Following line instanciates web service and adds the correct URL from settings
ionSyncPlugin.ionSyncWS.Webservice ionPmWS = Library.InitWebservice();
ionPmWS.GetUserProjectsCompleted += new ionSyncPlugin.ionSyncWS.GetUserProjectsCompletedEventHandler(getProjectsCompleted);
ionPmWS.GetUserProjectsAsync(settings.Login,Library.GetMD5(settings.Password));
}
private static void getProjectsCompleted(object sender, ionSyncPlugin.ionSyncWS.GetUserProjectsCompletedEventArgs e)
{
// Do some stuff with the result
}
}
[/code]
<br/>
<div class=qt style=" <br/>
When the program starts, the first Sync (being started from Startup()) <br/> works fine. But whenever the timer fires the elapsed event, the <br/> program performs a request, but the getProjectsCompleted eventhandler <br/> is never started. <br/>
According to my findings, the request reaches the web service, and the <br/> method (getProjects) is being processed on server side successfully. <br/> Ive also tried testing the application with the web service running <br/> locally in Visual Studio. The result was the same.
Ive tried setting up the timer object inside the Core class instead <br/> of the application class, but the result was just the same.
Can anyone explain to me why this is happening ?
Thanks in advance!
Kind regards, <br/> Mathew
View the full article