Welcome to Dream.In.Code
Become a C# Expert!

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




How can i make a delay for this .... ?

2 Pages V  1 2 >  
Reply to this topicStart new topic

How can i make a delay for this .... ?

access2reality
26 Feb, 2008 - 09:08 AM
Post #1

New D.I.C Head
*

Joined: 10 Feb, 2008
Posts: 24


My Contributions
Hi,
I write this code for send back offline message's to user who comeing online and has offline message from some other user.

here is code of server (just for send back offline message to client):

CODE

string offlinemessagepath = PathUsers + User + "\\offline-message\\";
foreach (string Friend in Directory.GetDirectories(offlinemessagepath))
         {
             string readofflinepath = Friend + "\\offmessage.txt";
              foreach (string line in System.IO.File.ReadAllLines(readofflinepath))
                       {
                           string offline = line;
                           string message = "jjfnb876gtbuh2jk3fjiu78y6" + offline;
                           SendMsgToClient(message, socketData.m_clientNumber);
                        }
                            string delfile = Friend + "\\offmessage.txt";
                            File.Delete(delfile);
                            string deldic = Friend;
                            Directory.Delete(deldic);
                            
                            
          }


as you can see i read all offline message of a user from a text file. the problem is send speed of each line .
i mean becuse code runing from a computer "SendMsgToClient" runing to fast and client can get just 3 message per seconde . so i need make some delay for client .
i did try break point and in break point mode everything is ok and no problem at all becuse i send message whit delay (i mean whit human speed)

any idea?

thanks
User is offlineProfile CardPM
+Quote Post

zakary
RE: How Can I Make A Delay For This .... ?
26 Feb, 2008 - 09:22 AM
Post #2

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 420



Thanked: 8 times
Dream Kudos: 175
My Contributions
int timeInMilliseconds = 3000;

System.Threading.Thread.Sleep(timeInMilliseconds);
User is offlineProfile CardPM
+Quote Post

access2reality
RE: How Can I Make A Delay For This .... ?
27 Feb, 2008 - 06:38 AM
Post #3

New D.I.C Head
*

Joined: 10 Feb, 2008
Posts: 24


My Contributions
QUOTE(zakary @ 26 Feb, 2008 - 10:22 AM) *

int timeInMilliseconds = 3000;

System.Threading.Thread.Sleep(timeInMilliseconds);



Hi,
And thanks for your help and time .
i did what you told me it work but when the time is fineshed it doesn't come out of timer prosess and stay on timer .
do we have something to make this timer false after work?

thanks and i be waiting for your answer.


User is offlineProfile CardPM
+Quote Post

zakary
RE: How Can I Make A Delay For This .... ?
27 Feb, 2008 - 06:49 AM
Post #4

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 420



Thanked: 8 times
Dream Kudos: 175
My Contributions
There is but it is Dream In Code's Policy to guide people and help them not write their code, so you can post your code using "[code = csharp]" your code here "[\code]"

or you can check out this link
http://msdn2.microsoft.com/en-us/library/s...eep(VS.71).aspx
User is offlineProfile CardPM
+Quote Post

access2reality
RE: How Can I Make A Delay For This .... ?
27 Feb, 2008 - 07:58 AM
Post #5

New D.I.C Head
*

Joined: 10 Feb, 2008
Posts: 24


My Contributions
QUOTE(zakary @ 27 Feb, 2008 - 07:49 AM) *

There is but it is Dream In Code's Policy to guide people and help them not write their code, so you can post your code using "[code = csharp]" your code here "[\code]"

or you can check out this link
http://msdn2.microsoft.com/en-us/library/s...eep(VS.71).aspx


Hi,
I don't know what yhou mean?!!!
my code is firest post and i just add your code on that anyway i will copy the code :

CODE

                             string readofflinepath = Friend + "\\offmessage.txt";
                             foreach (string line in System.IO.File.ReadAllLines(readofflinepath))
                             {
                                
                                 string offline = line;
                                 string message = "jjfnb876gtbuh2jk3fjiu78y6" + offline;
                                 SendMsgToClient(message, socketData.m_clientNumber);
                                 int timeInMilliseconds = 1000;
                                 System.Threading.Thread.Sleep(timeInMilliseconds);
                                
                             }



any idea ?????!!!!!!!

thanks
User is offlineProfile CardPM
+Quote Post

zakary
RE: How Can I Make A Delay For This .... ?
27 Feb, 2008 - 12:09 PM
Post #6

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 420



Thanked: 8 times
Dream Kudos: 175
My Contributions
Sorry access, I am sick and didn't see the code in the first post.

anyway try this it should work perfectly

CODE

        string readofflinepath = Friend + "\\offmessage.txt";
        foreach (string line in System.IO.File.ReadAllLines(readofflinepath))
        {                  
            string offline = line;
            string message = "jjfnb876gtbuh2jk3fjiu78y6" + offline;
            SendMsgToClient(message, socketData.m_clientNumber);
            System.TimeSpan waitTime = new System.TimeSpan(0, 0, 1); // TimeSpan(hour,minutes,seconds)
            System.Threading.Thread.Sleep(waitTime);
        }

User is offlineProfile CardPM
+Quote Post

access2reality
RE: How Can I Make A Delay For This .... ?
28 Feb, 2008 - 01:48 PM
Post #7

New D.I.C Head
*

Joined: 10 Feb, 2008
Posts: 24


My Contributions
QUOTE(zakary @ 27 Feb, 2008 - 01:09 PM) *

Sorry access, I am sick and didn't see the code in the first post.

anyway try this it should work perfectly

CODE

        string readofflinepath = Friend + "\\offmessage.txt";
        foreach (string line in System.IO.File.ReadAllLines(readofflinepath))
        {                  
            string offline = line;
            string message = "jjfnb876gtbuh2jk3fjiu78y6" + offline;
            SendMsgToClient(message, socketData.m_clientNumber);
            System.TimeSpan waitTime = new System.TimeSpan(0, 0, 1); // TimeSpan(hour,minutes,seconds)
            System.Threading.Thread.Sleep(waitTime);
        }




Hi,
I did last thing but same problem .
it doesn't come out of timer huh.gif
any other idea ?
thanks

User is offlineProfile CardPM
+Quote Post

Jayman
RE: How Can I Make A Delay For This .... ?
28 Feb, 2008 - 03:48 PM
Post #8

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,327



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
What do you mean "it doesn't come out of timer"?

Using the Thread.Sleep method will basically cause your code to pause for the specified time, before it resumes running.

Describe in more detail what is going on.
User is offlineProfile CardPM
+Quote Post

zakary
RE: How Can I Make A Delay For This .... ?
29 Feb, 2008 - 04:38 AM
Post #9

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 420



Thanked: 8 times
Dream Kudos: 175
My Contributions
Jayman is correct we need more details. the Thread.Sleep method works perfectly my program pauses for the time I tell it to pause then it starts running again.
User is offlineProfile CardPM
+Quote Post

access2reality
RE: How Can I Make A Delay For This .... ?
29 Feb, 2008 - 06:19 AM
Post #10

New D.I.C Head
*

Joined: 10 Feb, 2008
Posts: 24


My Contributions
Hi,
Ok. i give you more info but if is not which you need just tell me and i give you more info .

first of all i explane what i want do and then i will tell you what i did and what i get as error.

as you know my program is a messanger like (yahoo messanger , .....) . in pm mode when 2 person start send pm to each other everything is ok and it work perfectly .
but if one of the user be offline and the other one try to send him/her a offline message i must save the text in a file and wait for next login of reciver person and when he/she login i must read line by line of message and send them to reciver .
but the problem is speed of text sending. it is to fast and my client just get 3 message per second .
so i want use a timer to hold prosses for 1/3 sec and then send next line for user .
as you can see in my code i read line by line and send them but when i use timer or method which "zakary" told me to use i get runtime error in some of my deleget's which is responsible for return add list to user who become online .
so i thought maybe the prosses doesn't come out of timer prosses and ....
just tell me which part of code you need to underestand problem i can copy peast it for you but don't ask me to copy all of my project that it isn't possible.

thanks and i be waiting for your quastion's .

This post has been edited by access2reality: 29 Feb, 2008 - 08:29 AM
User is offlineProfile CardPM
+Quote Post

access2reality
RE: How Can I Make A Delay For This .... ?
1 Mar, 2008 - 02:03 PM
Post #11

New D.I.C Head
*

Joined: 10 Feb, 2008
Posts: 24


My Contributions
QUOTE(access2reality @ 29 Feb, 2008 - 07:19 AM) *

Hi,
Ok. i give you more info but if is not which you need just tell me and i give you more info .

first of all i explane what i want do and then i will tell you what i did and what i get as error.

as you know my program is a messanger like (yahoo messanger , .....) . in pm mode when 2 person start send pm to each other everything is ok and it work perfectly .
but if one of the user be offline and the other one try to send him/her a offline message i must save the text in a file and wait for next login of reciver person and when he/she login i must read line by line of message and send them to reciver .
but the problem is speed of text sending. it is to fast and my client just get 3 message per second .
so i want use a timer to hold prosses for 1/3 sec and then send next line for user .
as you can see in my code i read line by line and send them but when i use timer or method which "zakary" told me to use i get runtime error in some of my deleget's which is responsible for return add list to user who become online .
so i thought maybe the prosses doesn't come out of timer prosses and ....
just tell me which part of code you need to underestand problem i can copy peast it for you but don't ask me to copy all of my project that it isn't possible.

thanks and i be waiting for your quastion's .


Hi,
Any help over here?
thanks

User is offlineProfile CardPM
+Quote Post

Jayman
RE: How Can I Make A Delay For This .... ?
1 Mar, 2008 - 03:27 PM
Post #12

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,327



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
What is the runtime error that you are getting? Copy and paste the exact error message that you are receiving.
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 05:59PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

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