Click here to Skip to main content
15,897,704 members
Home / Discussions / C#
   

C#

 
QuestionSetting scanner device property constants (WIA) Pin
Etienne_12320-Feb-11 23:57
Etienne_12320-Feb-11 23:57 
QuestionRS232 interfacing help Pin
wjbjnr20-Feb-11 23:56
wjbjnr20-Feb-11 23:56 
AnswerRe: RS232 interfacing help Pin
OriginalGriff21-Feb-11 0:05
mveOriginalGriff21-Feb-11 0:05 
AnswerRe: RS232 interfacing help Pin
Dalek Dave21-Feb-11 0:21
professionalDalek Dave21-Feb-11 0:21 
GeneralRe: RS232 interfacing help Pin
OriginalGriff21-Feb-11 0:54
mveOriginalGriff21-Feb-11 0:54 
GeneralRe: RS232 interfacing help Pin
wjbjnr21-Feb-11 10:50
wjbjnr21-Feb-11 10:50 
GeneralRe: RS232 interfacing help Pin
OriginalGriff21-Feb-11 21:51
mveOriginalGriff21-Feb-11 21:51 
Questionbuild a Dynamic code - c# 4.0 Pin
arkiboys20-Feb-11 23:17
arkiboys20-Feb-11 23:17 
I have developed a windows service (MainService) which monitors the messages sent from other windows services.
The MainService knows which services to monitor by reading The services names from settings.xml file.
At present in the settings.xml, there are several services names i.e. service1, service2, etc... which the MainService reads (using a foreach loop).

As you see below, the code shows how the MainService reads the settings and checks the previous time of the service message...

Question:

Everytime I add a new service name to the setting.xml, I have to duplicate the below code for the new service (But with new related variables i.e. _dtPreviousService?Time), etc ...

How can I make the code dynamic, so that if a new service name is added to the settings.xmml, then I do not have to add/duplicate code just to check the new service?...

Hope you see what I am trying to achieve?

Thank you

The c# code in the MainService is something similar to the following:
_dtPreviousService1Time datetime;
_dtPreviousService2Time datetime;
...
...

foreach(ServerMonitor item in monitorSettings)
{
    if (item.Servicename == "service1") //check for service1...
    {
       if (_dtPreviousService1Time != DateTime.MinValue)
       {
        TimeSpan span = PresentTime.Subtract(_dtPreviousService1Time);
        dblTimeDifference = span.TotalSeconds;
        _dtPreviousService1Time = PresentTime;//store as last (Previous) received time...
       }
       else
       {
       _dtPreviousService1Time = DateTime.Now;//first time round capturing messages...
       }
       
       break; //come out of the foreach loop...
    }
    elseif (item.Servicename == "service2") //check for the service2...
    {
     ...
     ...
     ...
    }

}

...
...
...

AnswerRe: build a Dynamic code - c# 4.0 Pin
Thomas Krojer20-Feb-11 23:34
Thomas Krojer20-Feb-11 23:34 
AnswerRe: build a Dynamic code - c# 4.0 Pin
dasblinkenlight20-Feb-11 23:37
dasblinkenlight20-Feb-11 23:37 
AnswerRe: build a Dynamic code - c# 4.0 Pin
RobCroll21-Feb-11 2:40
RobCroll21-Feb-11 2:40 
GeneralRe: build a Dynamic code - c# 4.0 Pin
arkiboys21-Feb-11 4:42
arkiboys21-Feb-11 4:42 
QuestionStatic or non-static method performance and thread safety? Pin
Chesnokov Yuriy20-Feb-11 21:54
professionalChesnokov Yuriy20-Feb-11 21:54 
AnswerRe: Static or non-static method performance and thread safety? Pin
dasblinkenlight20-Feb-11 23:50
dasblinkenlight20-Feb-11 23:50 
QuestionRe: Static or non-static method performance and thread safety? Pin
Chesnokov Yuriy21-Feb-11 0:53
professionalChesnokov Yuriy21-Feb-11 0:53 
AnswerRe: Static or non-static method performance and thread safety? Pin
dasblinkenlight21-Feb-11 4:30
dasblinkenlight21-Feb-11 4:30 
AnswerRe: Static or non-static method performance and thread safety? Pin
_Erik_21-Feb-11 3:15
_Erik_21-Feb-11 3:15 
QuestionRe: Static or non-static method performance and thread safety? Pin
Chesnokov Yuriy21-Feb-11 3:44
professionalChesnokov Yuriy21-Feb-11 3:44 
AnswerRe: Static or non-static method performance and thread safety? Pin
Luc Pattyn21-Feb-11 3:53
sitebuilderLuc Pattyn21-Feb-11 3:53 
QuestionRe: Static or non-static method performance and thread safety? Pin
Chesnokov Yuriy21-Feb-11 4:26
professionalChesnokov Yuriy21-Feb-11 4:26 
AnswerRe: Static or non-static method performance and thread safety? Pin
Luc Pattyn21-Feb-11 4:45
sitebuilderLuc Pattyn21-Feb-11 4:45 
AnswerRe: Static or non-static method performance and thread safety? Pin
_Erik_21-Feb-11 4:00
_Erik_21-Feb-11 4:00 
Questionusing Microsoft.Office.Interop.Word + timeout Pin
Member 769046020-Feb-11 18:26
Member 769046020-Feb-11 18:26 
AnswerRe: using Microsoft.Office.Interop.Word + timeout Pin
Dalek Dave20-Feb-11 22:13
professionalDalek Dave20-Feb-11 22:13 
GeneralRe: using Microsoft.Office.Interop.Word + timeout Pin
Member 769046020-Feb-11 22:15
Member 769046020-Feb-11 22:15 

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.