How can I not fall in "not responding " while doing long loop?


 
Thread Tools Search this Thread
Top Forums Programming How can I not fall in "not responding " while doing long loop?
# 1  
Old 12-21-2013
How can I not fall in "not responding " while doing long loop?

Hi .. I'm a student that I helped by you when I was learning c for unix..

I want to ask you about different thing this time and I know you can help me
be cause I like your style helping people..
I want to ask about .net c# ...

I did a simple program that make me control my windows system using c# like turning it off or lock it at certain time the user input.. it's like scheduler but a lot easier to use my problem is "sorry for the messy desktop"
Image
that my program will inter in a while loop until the system time = the input time.. and that cause a not responding and that is not efficient.. I tried to add "sleep" but that didn't work with it and still not responding on the while loop
any solutions to make it run normally.. this is a function of the code.."the others are same but a little different"

Code:
private void button1_Click(object sender, EventArgs e)
        {
            string clock;
            clock = textBox1.Text;
            System.Windows.Forms.MessageBox.Show("system will close in " + clock);
            if (radioButton1.Checked)
            {
                clock = clock + " AM";
            }
            if (radioButton2.Checked)
            {
                clock = clock + " PM";
            }
            while (DateTime.Now.ToString("h:mm tt") != clock) // here is the problem
            {
                if (DateTime.Now.ToString("h:mm tt") == clock)
                    break;
               

            }
            
            System.Diagnostics.Process.Start("shutdown", "/s /t 0");
            this.Close();
        }

# 2  
Old 12-27-2013
Where did you try the sleep? One time test >= is better, in case you sleep past.
This User Gave Thanks to DGPickett For This Post:
# 3  
Old 12-28-2013
i think using timer control and timer_tick event would be better. Google it.
This User Gave Thanks to kg_gaurav For This Post:
# 4  
Old 12-30-2013
However, it sounds like your routine call might have been in a interrupts masked state, so you may need to hand off alarming to another thread and return to get interrupts serviced.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

3. Shell Programming and Scripting

Does processing "fall through" functions? Plus...

Hi, I'm new here, and hope that someone can help explain how a script that I'm working with works? The code looks like this: #!/bin/bash export PATH=$PATH:.:/usr/sbin:/sbin function validate_xxx() { echo "validating xxx parameters" if ; then . . (7 Replies)
Discussion started by: ohaya
7 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. UNIX for Dummies Questions & Answers

BASH: Interactive "cp" (and "mv") in a loop

Hi. I have a copy-file script (and a move-file script) that I recently tried to make interactive. I tested the former on three files from a text list, and watched to see what would happen. As the cp command was in a while/do/done loop, there was no pause for input: it wrote the file from the... (2 Replies)
Discussion started by: SilversleevesX
2 Replies

7. Solaris

Locate NFS "not responding still trying" application on client

At times I have unknown applications that hang for long periods of time over and over again after a network glitch. These are sometimes nfs4 but usually nfs3 clients and are always solaris10 systems. nfs: NFS server hostname not responding still trying nfs: NFS server hostname ok nfs: NFS... (1 Reply)
Discussion started by: HPAVC
1 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question