首页 新闻 赞助 找找看

最近在写调用环信api的程序,求一段代码来图片每秒钟调用30次接口的方法?

0
悬赏园豆:10 [已解决问题] 解决于 2015-11-20 09:57

我想着是程序自动调用接口每秒钟满30次以后等待到下一秒在调用30以此类推,就是保证每次调用都在每秒30次以内,求端控制台或者web程序代码

黑山妖的主页 黑山妖 | 初学一级 | 园豆:4
提问于:2015-11-19 08:29
< >
分享
最佳答案
0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();
            p.RetryCalculator();

            for (int i = 0; i < 100; i++)
            {
                p.OutSideInvoke();
                Thread.Sleep(30);
            }
        }



        /// <summary>
        /// 调用的代码
        /// </summary>
        public void OutSideInvoke()
        {
            if (count>=0)
            {

                //在这里写你调用的代码
                Console.WriteLine("我在这里调用了");
                Console.WriteLine(count);

                //把数据减1,如果减到0就不能再使用了
                count--;
            }


        }

        private volatile static int count=30;

        private System.Timers.Timer timer;
        public void RetryCalculator()
        {
            if (timer != null)
            {
                timer.Dispose();
            }
            timer = new System.Timers.Timer();
            timer.Elapsed += timer_Elapsed;
            timer.Interval = 1000;
            timer.Start();
        }

        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            count = 30;
        }
    }


}
需要格局 | 老鸟四级 |园豆:2145 | 2015-11-20 09:18
其他回答(1)
0

多线程啊 一个线程执行30次 控制这个线程执行1秒就结束 开始下一个线程

收获园豆:10
丫的 | 园豆:1575 (小虾三级) | 2015-11-19 11:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册