Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,069 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,611 people online right now. Registration is fast and FREE... Join Now!




How to make thread to sleep for one hour

 
Reply to this topicStart new topic

How to make thread to sleep for one hour

Mythili
8 Apr, 2008 - 10:18 PM
Post #1

New D.I.C Head
*

Joined: 8 Apr, 2008
Posts: 3

hi
i m working in asp.net with c#. in my application i want to send notification to administrator about their password expiration. i tried thread for this. It works fine when i give time interval upto 20min. but if i make thread to sleep for an hour it is not working. i dont know how to do this...

can anyone help me to solve this problem...
here is my code...
CODE

public void fn()
        {
           MailMessage mm = new MailMessage();
            while (true)
            {
                mm.From = new System.Net.Mail.MailAddress("pwdreset@tcs.com");
                mm.To.Add("administrator@book.com");
                mm.IsBodyHtml = true;
                mm.Body += "Dear administrator, <br><br>";
                mm.Body += "You have only 7 days to reset your password.";
                            
                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(host, 25);
                client.Send(mm);
                [b]Thread.Sleep(TimeSpan.FromHours(1));[/b]
            }
      }

public void note()
        {
            Thread th;
            ThreadStart thstart = new ThreadStart(fn);
            th = new Thread(thstart);
            th.Start();
        }

User is offlineProfile CardPM
+Quote Post

zakary
RE: How To Make Thread To Sleep For One Hour
9 Apr, 2008 - 05:17 AM
Post #2

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 404



Thanked: 6 times
Dream Kudos: 175
My Contributions
try Thread.Sleep(3600000); the 3600000 is Milliseconds for a hour. I assume your thstart method is located some where else and that is where you want to call the Thread.Sleep method.
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: How To Make Thread To Sleep For One Hour
9 Apr, 2008 - 08:13 AM
Post #3

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,198



Thanked: 213 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Just to clarify this for zakary, thstart here is a delegate instance (of type ThreadStart which is defined in the .NET framework in the namespace System.Threading). It isn't a method nor contains any body of code. It is only used to get a reference to the entrypoint method for the thread... in this case is his fn() method defined there.

Just thought I would point that out to those who may have misunderstood the example. icon_up.gif

This post has been edited by Martyr2: 9 Apr, 2008 - 08:14 AM
User is offlineProfile CardPM
+Quote Post

zakary
RE: How To Make Thread To Sleep For One Hour
9 Apr, 2008 - 08:20 AM
Post #4

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 404



Thanked: 6 times
Dream Kudos: 175
My Contributions
I see that now I only saw one instance of thstart but now I see I over looked it. I guess cuz I always write my Threads like

Thread th = new Thread( new ThreadStart(fn) );

th.Start();

sorry for my incorrect post.
but Thread.Sleep(3600000); in the fn method will work for the hour sleep

This post has been edited by zakary: 9 Apr, 2008 - 08:22 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 07:01PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month