Link to home
Start Free TrialLog in
Avatar of ocaccy
ocaccyFlag for Japan

asked on

C# - Button with time

Button with time to perform the tasks for a period and stop automatically in time configured.
Any idea is welcome.

ocaccy
ASKER CERTIFIED SOLUTION
Avatar of mcs0506
mcs0506
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ocaccy

ASKER

Hi,

If I need 10 minutes,

This is OK?
DateTime stopTime = DateTime.Now + TimeSpan(0, 0, 10, 0);
while(stopTime > DateTime.Now)
{
  //do code
}

Open in new window

Avatar of ocaccy

ASKER

User generated image User generated image
Why?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ocaccy

ASKER

Not stopping and not delay the execution of the program.
How to play an mp3 of 1.5 seconds here?

ocaccy
/// <summary>
        /// COUNT 1st time, 2nd time and 3rd time.
        /// </summary>
        private void timer3_Tick(object sender, EventArgs e)
        {
            int i_KyuSoku = Convert.ToInt32(nUD_KyuSoku.Value);
            int i_RyuSoku = Convert.ToInt32(nUD_RyuSoku.Value);
            int i_Seiti = Convert.ToInt32(nUD_Seiti.Value);
            int i_2sEstagios = i_KyuSoku + i_RyuSoku;
            int i_3sEstagios = i_KyuSoku + i_RyuSoku + i_Seiti;

            TimeSpan ts = DateTime.Now.Subtract(inicio);
            lbl_crono.Text = (string.Format("{0:00}:{1:00}:{2:00}", (int)ts.TotalHours, ts.Minutes, ts.Seconds));

            TimeSpan ts1 = TimeSpan.FromSeconds(i_KyuSoku + 1);
            string txtDate1 = string.Format("Full time: {0}", new DateTime(ts.Ticks).ToString("HH:mm:ss"));

            TimeSpan ts2 = TimeSpan.FromSeconds(i_RyuSoku + 1);
            string txtDate2 = string.Format("Full time: {0}", new DateTime(ts.Ticks).ToString("HH:mm:ss"));

            TimeSpan ts3 = TimeSpan.FromSeconds(i_Seiti + 1);
            string txtDate3 = string.Format("Full time: {0}", new DateTime(ts.Ticks).ToString("HH:mm:ss"));

            TimeSpan ts22 = TimeSpan.FromSeconds(i_2sEstagios + 1);
            //string txtDate3 = string.Format("Full time: {0}", new DateTime(ts.Ticks).ToString("HH:mm:ss"));

            TimeSpan ts33 = TimeSpan.FromSeconds(i_3sEstagios);
            //string txtDate3 = string.Format("Full time: {0}", new DateTime(ts.Ticks).ToString("HH:mm:ss"));

            if (ts <= ts1)
            {
                label152.Visible = false;
                label153.Visible = false;
                label154.Visible = false;
                label155.Visible = false;
                label151.Visible = true;
            }

            if (ts > ts1 && ts <= ts22)
            {
                label151.Visible = false;
                label152.Visible = true;
            }

            if (ts > ts1 && ts > ts22 && ts <= ts33)
            {
                // i see one stop in the flow with this:    
                DateTime stopTime = DateTime.Now.AddSeconds(2);
                while (stopTime > DateTime.Now)
                {
                     System.Media.SystemSounds.Beep.Play();
                    // Not stopping and not delay the execution 
                    // of the program.
                    // How to play an mp3 of 1.5 seconds here? 
                }
               
                label151.Visible = false;
                label152.Visible = false;
                label153.Visible = true;
                label154.Visible = true;
 
            }

            if (ts > ts33)
            {
                timer3.Stop();
                timer_10.Stop();
                label151.Visible = false;
                label152.Visible = false;
                label153.Visible = false;
                label154.Visible = false;
                label155.Visible = true;
                //timer_10.Enabled = true;
                
            }
        }

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ocaccy

ASKER

I still do not know how to use, so I put the code as the previous model.

I have a time routine.
Also has an alarm sound with duration of 1.5 seconds.
This format mpe3, but can transform to wav.

When give a x time, I want to play this sound, but I want to continue running normally.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ocaccy

ASKER

Ok, but, how to this sound play only one time?
As I did, every second restart, and processing delays.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ocaccy

ASKER

Hi,

sorry for the confusion.

I want to play a file of 1.5 seconds, just one time.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ocaccy

ASKER

Hi, I put the play alone in another condition.