How to execute the loop for specific time

后端 未结 7 1032
心在旅途
心在旅途 2020-12-05 13:37

How can i execute the a particluar loop for specified time

Timeinsecond = 600

int time = 0;
while (Timeinsecond > time)
{
   // do something here
}


        
相关标签:
7条回答
  • 2020-12-05 14:25
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Accord.Video.FFMPEG;
    
    
    namespace TimerScratchPad
    {
        public partial class Form1 : Form
        {
            VideoFileWriter writer = new VideoFileWriter();
            int second = 0;
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                writer.VideoCodec = VideoCodec.H264;
                writer.Width = Screen.PrimaryScreen.Bounds.Width;
                writer.Height = Screen.PrimaryScreen.Bounds.Height;
                writer.BitRate = 1000000;
                writer.Open("D:/DemoVideo.mp4");
    
                RecordTimer.Interval = 40;
                RecordTimer.Start();
    
            }
    
            private void RecordTimer_Tick(object sender, EventArgs e)
            {
                Rectangle bounds = Screen.GetBounds(Point.Empty);
                using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
                {
                    using (Graphics g = Graphics.FromImage(bitmap))
                    {
                        g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
                    }
                    writer.WriteVideoFrame(bitmap);
                }
    
                textBox1.Text = RecordTimer.ToString();
                second ++;
                if(second > 1500)
                {
                    RecordTimer.Stop();
                    RecordTimer.Dispose();
                    writer.Close();
                    writer.Dispose();
                }
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题