begin process at 2012 02 10 14:11:57
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

.NET

 > HEURE EN TEMPS RÉEL

HEURE EN TEMPS RÉEL


 Information sur la source

Note :
6 / 10 - par 2 personnes
6,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :.NET Source .NET ( DotNet ) Classé sous :heure, temps, réel Niveau :Initié Date de création :24/09/2004 Vu :10 659

Auteur : gdupasqu

Ecrire un message privé
Commentaire sur cette source (2)
Ajouter un commentaire et/ou une note

 Description

Ce code affiche l'heure dans un "form" en temps réel. Deux thread sont crées :

1) Le "form"

2) Un thread appelé time Thread qui calcule l'heure, dort une seconde calcule l'heure, dort une seconde .... (en boucle) A chaque fois que le thread calcule l'heure, il l'affiche dans la "form".

Source

  • using System;
  • using System.Drawing;
  • using System.Collections;
  • using System.ComponentModel;
  • using System.Windows.Forms;
  • using System.Data;
  • using System.Threading;
  • namespace MyTime
  • {
  • /// <summary>
  • /// Summary for MyTime
  • /// </summary>
  • public class MyForm : System.Windows.Forms.Form
  • {
  • //{{OBJ_DECLARATION(MyTime.MyForm)
  • protected System.Windows.Forms.Label timeLabel;
  • //}}OBJ_DECLARATION
  • private Thread timeThread;
  • public MyForm()
  • {
  • // Required for Visual Forms support
  • InitializeComponent();
  • // TODO: Add any constructor code after InitializeComponent call
  • }
  • /// <summary>
  • /// Clean up any resources being used.
  • /// </summary>
  • protected override void Dispose( bool disposing )
  • {
  • base.Dispose( disposing );
  • }
  • /// <summary>
  • /// Required method for Visual Forms support - do not modify
  • /// the contents between the //{{ ... //}} tags.
  • /// </summary>
  • private void InitializeComponent()
  • {
  • //{{OBJ_INSTANTIATION(MyTime.MyForm)
  • this.timeLabel = new System.Windows.Forms.Label();
  • //}}OBJ_INSTANTIATION
  • this.SuspendLayout();
  • this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  • //{{OBJ_PROPERTIES(MyTime.MyForm.timeLabel)
  • this.timeLabel.Location = new System.Drawing.Point(30, 30);
  • this.timeLabel.Size = new System.Drawing.Size(140, 40);
  • this.timeLabel.TabIndex = 0;
  • this.timeLabel.Font = new System.Drawing.Font("Modern", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(255)));
  • //}}OBJ_PROPERTIES
  • this.timeLabel.Text = this.returnTime();
  • //{{FORM_PROPERTIES(MyTime.MyForm)
  • this.ClientSize = new System.Drawing.Size(200, 100);
  • this.Font = new System.Drawing.Font("MS Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  • this.Controls.Add(this.timeLabel);
  • //}}FORM_PROPERTIES
  • this.Text = this.returnDate();
  • this.Name = "MyForm";
  • //this.Text = "MyForm";
  • this.ResumeLayout(false);
  • timeThread = new Thread(new ThreadStart(timeLive));
  • timeThread.Start();
  • }
  • string returnDate(){
  • string dateNow = null;
  • DateTime now = DateTime.Now;
  • dateNow = now.Day + "." + now.Month + "." + now.Year ;
  • return dateNow;
  • }
  • string returnTime(){
  • string timeNow = null;
  • int hour;
  • int minute;
  • int second;
  • string hS, mS, sS;
  • DateTime now = DateTime.Now;
  • hour = now.Hour;
  • minute = now.Minute;
  • second = now.Second;
  • if( hour < 10 )
  • hS = "0" + hour;
  • else
  • hS = "" + hour;
  • if( minute < 10)
  • mS = "0" + minute;
  • else
  • mS = "" + minute;
  • if( second < 10 )
  • sS = "0" + second;
  • else
  • sS = "" + second;
  • timeNow = hS + ":" + mS + ":" + sS ;
  • return timeNow;
  • }
  • private void timeLive()
  • {
  • while(true)
  • {
  • this.timeLabel.Text = this.returnTime();
  • Thread.Sleep(1000);
  • }
  • }
  • /// <summary>
  • /// The main entry point for the application.
  • /// </summary>
  • static void Main()
  • {
  • Application.Run(new MyForm());
  • }
  • }
  • }
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;

namespace MyTime
{

	/// <summary>
	/// Summary for MyTime
	/// </summary>
	public class MyForm : System.Windows.Forms.Form
	{
	

		//{{OBJ_DECLARATION(MyTime.MyForm)
		protected System.Windows.Forms.Label timeLabel;
		//}}OBJ_DECLARATION
		
		private Thread timeThread;
	
		public MyForm()
		{
		// Required for Visual Forms support
			InitializeComponent();

		// TODO: Add any constructor code after InitializeComponent call
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}

		/// <summary>
		/// Required method for Visual Forms support - do not modify
		/// the contents between the //{{ ... //}} tags.
		/// </summary>
		private void InitializeComponent()
		{			
			//{{OBJ_INSTANTIATION(MyTime.MyForm)
			this.timeLabel = new System.Windows.Forms.Label();
			//}}OBJ_INSTANTIATION
			
			this.SuspendLayout();
						
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			
			//{{OBJ_PROPERTIES(MyTime.MyForm.timeLabel)
			this.timeLabel.Location = new System.Drawing.Point(30, 30);
			this.timeLabel.Size = new System.Drawing.Size(140, 40);
			this.timeLabel.TabIndex = 0;
			this.timeLabel.Font = new System.Drawing.Font("Modern", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(255)));
			//}}OBJ_PROPERTIES
			
			this.timeLabel.Text = this.returnTime();

			//{{FORM_PROPERTIES(MyTime.MyForm)
			this.ClientSize = new System.Drawing.Size(200, 100);
			this.Font = new System.Drawing.Font("MS Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Controls.Add(this.timeLabel);
			//}}FORM_PROPERTIES
			
			this.Text = this.returnDate();
			
			this.Name = "MyForm";
			//this.Text = "MyForm"; 
			
			this.ResumeLayout(false); 
			
			
			timeThread = new Thread(new ThreadStart(timeLive));
			timeThread.Start();		
		}
		
		
		string returnDate(){
			string dateNow = null;
			DateTime now = DateTime.Now;
			dateNow = now.Day + "." + now.Month + "." + now.Year ;
			return dateNow;
		}
		
		
		string returnTime(){
			string timeNow = null;
			int hour;
			int minute;
			int second;
			string hS, mS, sS;

			DateTime now = DateTime.Now;
			hour = now.Hour;
			minute = now.Minute;
			second = now.Second;

			if( hour < 10 )
				hS = "0" + hour;
			else
				hS = "" + hour;
				
			if( minute < 10)
				mS = "0" + minute;
			else
				mS = "" + minute;
				
			if( second < 10 )
				sS = "0" + second;
			else 
				sS = "" + second;
			
			timeNow = hS + ":" + mS + ":" + sS ;			
			return timeNow;
		}
		
		private void timeLive()
		{
			while(true)
			{
				this.timeLabel.Text = this.returnTime(); 	
				Thread.Sleep(1000);
			}
		}
		

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		static void Main() 
		{

			Application.Run(new MyForm());
		}

	}
}



 Sources de la même categorie

Source avec Zip Source avec une capture Source .NET (Dotnet) ORIONBANQUE par toutphp
Source avec Zip Source avec une capture Source .NET (Dotnet) ORIONAPPLICATION par toutphp
Source avec Zip SOCKET CONNEXION CLIENT & SERVEUR par ziedto83
Source avec Zip Source .NET (Dotnet) FFMPEG.NET : WRAPPER .NET DE FFMPEG par MasterShadows
Source avec Zip Source .NET (Dotnet) ATTACHER, CRÉER ET SAUVEGARDER UNE BASE DE DONNÉES SQL SERVE... par Alvepinai

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture Source .NET (Dotnet) DIFFÉRENCE DE TEMPS, XML, POCKETPC / WINFORMS...... par Steph115
Source avec Zip Source avec une capture Source .NET (Dotnet) NETTOYEUR DE DOSSIERS par mahhoura
Source avec Zip Source avec une capture Source .NET (Dotnet) HORLOGE/ALARME NUMÉRIQUE par Bio3G
Source avec Zip Source avec une capture Source .NET (Dotnet) COMPTE À REBOURS par Azema
Source .NET (Dotnet) CLASSE DATE AVEC QUELQUES FONCTIONS par ricklekebekoi

Commentaires et avis

Commentaire de bucherb le 05/10/2004 10:19:17

C'est un peu beaucoup de faire une mise à jour toute les secondes je trouve :-/  J'avais fais le même système qui se met a jour toutes les minutes, et qui garde une précision redoutable lol

Commentaire de Infinity05 le 25/04/2010 15:49:10 4/10

Il y a un gros problème le processus continue de tourner même après avoir fermé le programme :/
Donc si on l'ouvre 3 fois et qu'on le ferme 3 fois il y a toujours 3 processus en cours dans le gestionnaire des tâches sachant qu'un processus prend plus ou moins 4Mo de RAM.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

manipulation de DateTime [ par Thanos_the_yopper ] en fait, je voudrais récupérer l'heure exact ou à été exécuter un évenement , et vérifier qu'il s'est bien passé un certain laps de temps avec de pouv interval de temps en minuit [ par dhabasse ] Salut tout le mondej'espere qu'il aura quelq'un pour m'aider comme je le trouve toujour dans ce forum.avec deux DateTimePicker  dtp1 et dtp2 en format Output (temps réel) commande DOS [ par OSiRiSPaulux ] Salut tlm, je suis actuellement sur un projet de frontend pour un logiciel en ligne de commande sous DOS; je souhaiterai savoir s'il existe un composa Compteur de ligne temps réel [ par ricklekebekoi ] Apres toutes ces questions, vous aurez sur ce site un éventail complet des propriétés du richtextbox :pDonc, j'aimerais afficher les lignes a gauche d Création de jeu de stratégie temps réel recherche d'équipe [ par pvpnd8 ] Création de jeu de stratégie temps réel. Salut à tous je me présente Ecriture log temps réel [ par vantoora ] Bonjour,Voilà j'ai développé un petit programme qui fait une (ou plutôt) comparaison de plusieurs dossiers dans une arborescence quelconque dans un se Déclencher une fonction à un temps précis [ par bubbathemaster ] Bonjour,Je sais, c'est sans doute une question conne mais j'ai pas trouvé...Comment déclencher en C# un évènement à une heure précise de la journée et Animation temps réel d'avatar 3D [ par zanzan ] Bonjour Je cherche une API pour afficher un personnage 3d que je pourrais animer en temps réel, le tout sous c#. L'idée est de le faire réagir en fonc Additionner les éléments d'une listbox - C# - [ par Dhazel ] Bonjour, Je souhaiterais obtenir de l'aide concernant des listbox : Pour situer mon soucis je suis dans un projet Windows Form Visual 2005 en c#, Sur


Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,934 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales