Click here to Skip to main content
15,920,896 members
Home / Discussions / C#
   

C#

 
AnswerRe: Value type vs reference type Pin
rah_sin10-Oct-08 0:17
professionalrah_sin10-Oct-08 0:17 
AnswerRe: Value type vs reference type Pin
DaveyM6910-Oct-08 0:17
professionalDaveyM6910-Oct-08 0:17 
GeneralRe: Value type vs reference type Pin
Mogaambo10-Oct-08 0:26
Mogaambo10-Oct-08 0:26 
GeneralRe: Value type vs reference type Pin
DaveyM6910-Oct-08 1:21
professionalDaveyM6910-Oct-08 1:21 
GeneralRe: Value type vs reference type Pin
DaveyM6910-Oct-08 2:20
professionalDaveyM6910-Oct-08 2:20 
GeneralRe: Value type vs reference type Pin
Mogaambo10-Oct-08 2:23
Mogaambo10-Oct-08 2:23 
GeneralRe: Value type vs reference type Pin
DaveyM6910-Oct-08 2:39
professionalDaveyM6910-Oct-08 2:39 
Generalwindows service - Day light Time saving handling Pin
raju_golla9-Oct-08 23:51
raju_golla9-Oct-08 23:51 
Hi
I have a windows service application that reads service 'StartTime' , 'IntervalTime' from configuration file and runs my method that do the job at specified time and time intervals. That works absolutely fine by reading the start time and Interval Time (interval time to wait to run the service again).

But the problem is when yearly timings changes. In United Kingdom we get timings change twice explained below for this year. This varies year to year:

Clocks went forward one hour on Sunday 30 March 01:00 GMT* (02:00 BST)

* As the UK is currently on GMT, we changed our clocks at 1 am on Sunday 30 March.

Clocks moved one hour backwards. Sunday 26 October 02:00 BST** (01:00 GMT )

**As the UK is currently on BST (British Summer Time), we will change our clocks at 2 am on Sunday 26th October.


How it works just now:
Currently my service starts at start Time specified in configuration file and again after specified interval Time in config file. For example 1000 is start time and interval Time[should be specified in milli seconds] is 86400000[Equals 24hrs]. My service starts at 1000 Today and runs and then sleep for 24hrs AGAIN runs at NEXT DAY 1000. During this 24hours sleeping if day light time is changing, my service will be out of sync.

Only change i like to be done is: Timer object checks system time every minute to find out if it is the time to run the service or not. That way we can hanlde day light savings time changes i think.

Note: May be by checking time every minute to see if current Time is the Time to run the service method or not.

1 public partial class myService : ServiceBase   
2   
3     {   
4   
5         //Initialize an instance of Timer   
6   
7         System.Threading.Timer timer;   
8   
9          public myService()   
10   
11         {               
12          InitializeComponent();    
13         }   
14   
15          protected override void OnStart(string[] args)   
16   
17         {   
18   
19             try  
20   
21             {   
22   
23                 //Service Start Time read from app.config    
24   
25                 string startTimeString = ConfigurationSettings.AppSettings           ["StartTime"].ToString();   
26   
27                 //value to pass to callback function   
28   
29                 DateTime startTime;   
30   
31                 //how long to delay in milliseconds before calling the method   
32   
33                 int millisecondsToStart = 0;   
34     
35                 if (DateTime.TryParseExact(startTimeString, "HHmm", CultureInfo.InvariantCulture, DateTimeStyles.None, out startTime))   
36   
37                 {   
38   
39                     if (DateTime.Now > startTime)   
40   
41                         startTime = startTime.AddDays(1);   
42   
43                     millisecondsToStart = (int)startTime.Subtract(DateTime.Now).TotalMilliseconds;   
44   
45                 }   
46     
47                 timer = new System.Threading.Timer(OnElapsedTime, null, millisecondsToStart, Convert.ToInt32(ConfigurationSettings.AppSettings["intervalTime"]));   
48   
49   
50             }   
51   
52             catch (Exception ex)   
53   
54             {   
55   
56                 //write exception to Event Log   
57   
58                 System.Diagnostics.EventLog.WriteEntry("error in starting my Service", ex.Message + Environment.NewLine + ex.StackTrace);   
59   
60             }   
61   
62         }   
63   
64     
65   
66         protected override void OnStop()   
67   
68         {   
69   
70             //Nothing to do here   
71   
72         }   
73   
74          private void OnElapsedTime(object source)   
75   
76         {   
77   
78             //Call the method   
79   
80             TransferData();   
81         }  

GeneralRe: windows service - Day light Time saving handling Pin
Ashfield10-Oct-08 0:29
Ashfield10-Oct-08 0:29 
GeneralRe: windows service - Day light Time saving handling Pin
raju_golla10-Oct-08 0:37
raju_golla10-Oct-08 0:37 
QuestionDebug method for unhandled Thread and AppDomain.CurrentDomain Exceptions Pin
matixsc9-Oct-08 23:23
professionalmatixsc9-Oct-08 23:23 
Question[Message Deleted] Pin
sachinss19869-Oct-08 23:11
sachinss19869-Oct-08 23:11 
AnswerRe: Row deletion problem in Data grid Pin
Mycroft Holmes9-Oct-08 23:20
professionalMycroft Holmes9-Oct-08 23:20 
AnswerRe: Row deletion problem in Data grid Pin
DaveyM699-Oct-08 23:29
professionalDaveyM699-Oct-08 23:29 
QuestionWhere does Settings.Default.MySetting come from? Pin
buchstaben9-Oct-08 22:17
buchstaben9-Oct-08 22:17 
AnswerRe: Where does Settings.Default.MySetting come from? Pin
Simon P Stevens9-Oct-08 22:33
Simon P Stevens9-Oct-08 22:33 
GeneralRe: Where does Settings.Default.MySetting come from? Pin
buchstaben9-Oct-08 23:24
buchstaben9-Oct-08 23:24 
AnswerRe: Where does Settings.Default.MySetting come from? Pin
Mycroft Holmes9-Oct-08 23:22
professionalMycroft Holmes9-Oct-08 23:22 
QuestionRestore application from system tray when clicking the application's desktop shortcut icon in c# Pin
jairaj9-Oct-08 22:06
jairaj9-Oct-08 22:06 
AnswerRe: Restore application from system tray when clicking the application's desktop shortcut icon in c# Pin
DaveyM699-Oct-08 23:16
professionalDaveyM699-Oct-08 23:16 
AnswerRe: Restore application from system tray when clicking the application's desktop shortcut icon in c# Pin
Giorgi Dalakishvili9-Oct-08 23:38
mentorGiorgi Dalakishvili9-Oct-08 23:38 
QuestionPause and continue threads Pin
Mc_Topaz9-Oct-08 20:44
Mc_Topaz9-Oct-08 20:44 
AnswerRe: Pause and continue threads Pin
Jimmanuel10-Oct-08 3:16
Jimmanuel10-Oct-08 3:16 
GeneralRe: Pause and continue threads Pin
Mc_Topaz10-Oct-08 3:50
Mc_Topaz10-Oct-08 3:50 
GeneralRe: Pause and continue threads Pin
S. Senthil Kumar10-Oct-08 5:22
S. Senthil Kumar10-Oct-08 5:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.