Click here to Skip to main content
15,892,298 members
Home / Discussions / C#
   

C#

 
GeneralRe: Async vs Sync Pin
Luc Pattyn16-Nov-10 13:57
sitebuilderLuc Pattyn16-Nov-10 13:57 
QuestionAccessing form controls from WCF service Pin
teknolog12315-Nov-10 10:29
teknolog12315-Nov-10 10:29 
AnswerRe: Accessing form controls from WCF service Pin
Dave Kreskowiak15-Nov-10 10:49
mveDave Kreskowiak15-Nov-10 10:49 
AnswerRe: Accessing form controls from WCF service Pin
DaveyM6915-Nov-10 13:00
professionalDaveyM6915-Nov-10 13:00 
AnswerRe: Accessing form controls from WCF service Pin
PIEBALDconsult15-Nov-10 14:22
mvePIEBALDconsult15-Nov-10 14:22 
AnswerRe: Accessing form controls from WCF service Pin
si2480315-Nov-10 22:45
si2480315-Nov-10 22:45 
GeneralRe: Accessing form controls from WCF service Pin
teknolog12316-Nov-10 3:17
teknolog12316-Nov-10 3:17 
AnswerRe: Accessing form controls from WCF service Pin
si2480316-Nov-10 4:51
si2480316-Nov-10 4:51 
Hi again,

Well, start by creating a method in your Forms project that does just that, recieves the time info, and updates the controls. You can do this with

public void updateTime(int timeSpan){
   for each(Control c in this.Controls){
      c.doSomething();
   }
}


then, all you need to do is spawn a thread that wakes up every few minutes (or whatever period of time you want) and access the web service and retrieve the time information from your server. When it wakes up, it calls the method mentioned earlier.
The code i'm about to throw in here is by no means a product of good coding practices and will definitelly have bugs as i'm writing it directly on the reply from here at CodeProject, but might just do the trick.

public class Scheduler : Thread {
   private Form parentForm;
   private "WebServiceProxy" webServiceProxy;
   
   public Scheduler(Form mainForm){
      this.parentForm = mainForm;
      this.webServiceProxy = new "WebServiceProxy"();
   }

   public override void Run() {
      while(true) {
         int timeSpan = webServiceProxy.getTimeSpan(); // get the time elapsed
         sleep(5000); // will suspend thread execution for 5 seconds
      }
   }   
}


Now add an instance of the Scheduler to your main form.
In the constructor of your form (or at the InitializeComponent method) initialize the Scheduler field and call the Run() method on it.

Try it for yourself.
Hope it helps
GeneralRe: Accessing form controls from WCF service Pin
teknolog12318-Nov-10 7:34
teknolog12318-Nov-10 7:34 
AnswerRe: Accessing form controls from WCF service Pin
Daniel Vaughan15-Nov-10 23:41
Daniel Vaughan15-Nov-10 23:41 
Question"No connection could be made because the target machine actively refused it" Pin
Megidolaon14-Nov-10 22:31
Megidolaon14-Nov-10 22:31 
AnswerRe: "No connection could be made because the target machine actively refused it" Pin
Manfred Rudolf Bihy14-Nov-10 22:49
professionalManfred Rudolf Bihy14-Nov-10 22:49 
GeneralRe: "No connection could be made because the target machine actively refused it" Pin
Megidolaon14-Nov-10 22:56
Megidolaon14-Nov-10 22:56 
GeneralRe: "No connection could be made because the target machine actively refused it" Pin
Manfred Rudolf Bihy14-Nov-10 22:58
professionalManfred Rudolf Bihy14-Nov-10 22:58 
AnswerRe: "No connection could be made because the target machine actively refused it" Pin
Luc Pattyn15-Nov-10 3:37
sitebuilderLuc Pattyn15-Nov-10 3:37 
Questionthreshold filter problem Pin
pancakeleh14-Nov-10 22:03
pancakeleh14-Nov-10 22:03 
AnswerRe: threshold filter problem PinPopular
OriginalGriff14-Nov-10 23:27
mveOriginalGriff14-Nov-10 23:27 
GeneralIMPORT EXCEL TO SQL Pin
black0714-Nov-10 21:52
black0714-Nov-10 21:52 
GeneralRe: IMPORT EXCEL TO SQL Pin
Dave Kreskowiak15-Nov-10 2:00
mveDave Kreskowiak15-Nov-10 2:00 
GeneralRe: IMPORT EXCEL TO SQL Pin
musefan15-Nov-10 2:33
musefan15-Nov-10 2:33 
QuestionXML Serialization Pin
NarVish14-Nov-10 21:18
NarVish14-Nov-10 21:18 
AnswerRe: XML Serialization Pin
Manfred Rudolf Bihy14-Nov-10 22:02
professionalManfred Rudolf Bihy14-Nov-10 22:02 
GeneralRe: XML Serialization Pin
NarVish14-Nov-10 22:09
NarVish14-Nov-10 22:09 
GeneralRe: XML Serialization Pin
Manfred Rudolf Bihy14-Nov-10 22:14
professionalManfred Rudolf Bihy14-Nov-10 22:14 
GeneralRe: XML Serialization Pin
NarVish14-Nov-10 22:31
NarVish14-Nov-10 22:31 

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.