• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Worker类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Worker的典型用法代码示例。如果您正苦于以下问题:C# Worker类的具体用法?C# Worker怎么用?C# Worker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Worker类属于命名空间,在下文中一共展示了Worker类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ModelTraverser

		/// <summary>
		///   Initializes a new instance.
		/// </summary>
		/// <param name="createModel">Creates the model that should be checked.</param>
		/// <param name="output">The callback that should be used to output messages.</param>
		/// <param name="configuration">The analysis configuration that should be used.</param>
		internal ModelTraverser(Func<AnalysisModel> createModel, Action<string> output, AnalysisConfiguration configuration)
		{
			Requires.NotNull(createModel, nameof(createModel));
			Requires.NotNull(output, nameof(output));
			TransitionCollection.ValidateTransitionSizes();

			var tasks = new Task[configuration.CpuCount];
			var stacks = new StateStack[configuration.CpuCount];

			_loadBalancer = new LoadBalancer(stacks);
			Context = new TraversalContext(_loadBalancer, configuration, output);
			_workers = new Worker[configuration.CpuCount];

			for (var i = 0; i < configuration.CpuCount; ++i)
			{
				var index = i;
				tasks[i] = Task.Factory.StartNew(() =>
				{
					stacks[index] = new StateStack(configuration.StackCapacity);
					_workers[index] = new Worker(index, Context, stacks[index], createModel());
				});
			}

			Task.WaitAll(tasks);

			_states = new StateStorage(_workers[0].Model.StateVectorSize, configuration.StateCapacity);
			Context.States = _states;
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:34,代码来源:ModelTraverser.cs


示例2: Run

    public void Run()
    {
        const int num_workers = 4;
        Worker[] workers = new Worker[num_workers];
        Thread[] threads = new Thread[num_workers];

        for (int i = 0; i < num_workers; i++)
        {
            workers[i] = new Worker(i, 50);
            threads[i] = new Thread(workers[i].Run);
            threads[i].Start();
        }

        foreach (Thread t in threads)
            t.Join();

        foreach (Worker w in workers)
        {
            foreach (Expr e in w.result)
                Console.Write(" " + e);
            Console.WriteLine();
        }

        Console.WriteLine("done");
    }
开发者ID:ahorn,项目名称:z3test,代码行数:25,代码来源:thread.cs


示例3: Main

    static void Main()
    {
        // 创建线程对象。这不会启动该线程。
        Worker workerObject = new Worker();
        Thread workerThread = new Thread(workerObject.DoWork);

        // 启动辅助线程。
        workerThread.Start();
        Console.WriteLine("main thread: Starting worker thread...");

        // 循环直至辅助线程激活。
        while (!workerThread.IsAlive);

        // 为主线程设置 1 毫秒的休眠,
        // 以使辅助线程完成某项工作。
        Thread.Sleep(1);

        // 请求辅助线程自行停止:
        workerObject.RequestStop();

        // 使用 Join 方法阻塞当前线程,
        // 直至对象的线程终止。
        workerThread.Join();
        Console.WriteLine("main thread: Worker thread has terminated.");
    }
开发者ID:jetlive,项目名称:skiaming,代码行数:25,代码来源:ThreadStartStop.cs


示例4: Enter

    internal void Enter(ref Worker wr, Work work) {
      work.Next = null;

      var owner = Interlocked.Exchange(ref Tail, work);

      if (owner != null) {
        owner.Next = work;
      } else {
      Release:
        work.DoWork(ref wr);
        var prev = work;
        work = Volatile.Read(ref prev.Next);
        if (null != work)
          goto Release;

        if (prev == Interlocked.CompareExchange(ref Tail, null, prev))
          return;

      Spin:
        work = Volatile.Read(ref prev.Next);
        if (null != work)
          goto Release;
        goto Spin;
      }
    }
开发者ID:SmartCloudAI,项目名称:Hopac,代码行数:25,代码来源:WorkQueueLock.cs


示例5: Main

        public static void Main()
        {
            string[] studentData = Console.ReadLine()
                .Trim()
                .Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries);

            string firstStudentName = studentData[0];
            string lastStudentName = studentData[1];
            string facultyNumber = studentData[2];

            string[] workerData = Console.ReadLine()
                .Trim()
                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            string firstWorkerName = workerData[0];
            string lastWorkerName = workerData[1];
            double salary = double.Parse(workerData[2]);
            double workingHours = double.Parse(workerData[3]);

            try
            {
                Student student = new Student(firstStudentName, lastStudentName, facultyNumber);
                Worker worker = new Worker(firstWorkerName, lastWorkerName, salary, workingHours);

                Console.WriteLine(student);
                Console.WriteLine(worker);
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine(ae.Message);
            }
        }
开发者ID:IskraNikolova,项目名称:Object-oriented-programming,代码行数:32,代码来源:TestMain.cs


示例6: Main

		public static void Main(string[] args)
		{
			// Use Release Build to use jsc to generate java program
			// Use Debug Build to develop on .net

			Console.WriteLine("Robocode1. Crosscompiled from C# to Java.");

			// Extension methods...
			("This will take a few seconds...").ToConsole();

			Text = "Hello World";


			var w = new Worker { Count = 3, Delay = 1000 };

			w.Handler +=
				delegate
				{
					var n = DateTime.Now;

					Console.WriteLine(n.Hour + ":" + n.Minute + ":" + n.Second);
				};

			w.Invoke();

			Console.WriteLine(Text);
		}
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:27,代码来源:Program.cs


示例7: Main

    public static void Main()
	{
	    var worker = new Worker();
	    worker.Start();
	    Thread.Sleep(1000);
	    worker.Stop();	   
	}
开发者ID:ppatoria,项目名称:SoftwareDevelopment,代码行数:7,代码来源:non-volatile-issue.cs


示例8: DoWork

 public void DoWork(Worker d)
 {
     if (!Thread.CurrentThread.Equals((object) this.myThread))
     this.app.Dispatcher.Invoke(DispatcherPriority.Normal, (Delegate) d);
       else
     d();
 }
开发者ID:unbearab1e,项目名称:FlattyTweet,代码行数:7,代码来源:AppDispatcher.cs


示例9: ConvertWorkerViewModel_WhenValidViewModel_ReturnEntity

        public void ConvertWorkerViewModel_WhenValidViewModel_ReturnEntity()
        {
            var adrConv = new AddressConverter();
            var compConv = new CompetenceConverter();
            var converter = new WorkerConverter(adrConv,compConv,new ImageConverter());

            var viewModel = new WorkerViewModel
            {
                FirstName = "Filip",
                LastName = "Skurniak",
                Pesel = "632964328947",
                RelianceRating = 10,
                WorkerCompetences = new List<CompetenceViewModel>()
                {
                    new CompetenceViewModel
                    {
                        Id = 100
                    }
                }
            };
            var entity = new Worker();

            converter.ConvertViewModelToEntity(viewModel, entity);

            Assert.AreEqual(entity.FirstName, viewModel.FirstName);
        }
开发者ID:fsku,项目名称:temp-workers-hunter,代码行数:26,代码来源:ConvertersTests.cs


示例10: Invoke

 public override void Invoke(Worker.State state)
 {
     foreach (char ch in text)
     {
         TypeChar(ch);
     }
 }
开发者ID:pbalint,项目名称:Playground,代码行数:7,代码来源:TypeText.cs


示例11: Main

 static void Main(string[] args)
 {
     using (var worker = new Worker("localhost", "console", "failing"))
     {
         worker.Work();
     }
 }
开发者ID:gsimoes,项目名称:resque-sharp,代码行数:7,代码来源:Program.cs


示例12: Backend

 protected Backend(Object payload, Exception exception, Worker worker, String queue)
 {
     Exception = exception;
     Worker = worker;
     Queue = queue;
     Payload = payload;
 }
开发者ID:atorres757,项目名称:csharp-resque,代码行数:7,代码来源:Backend.cs


示例13: AsWorker

        public override Worker AsWorker()
        {
            Worker worker = new Worker("OTT", "Mathias Henrik Ottosen", 18, true, "Aalborg", "12345678", false, true, true);

            worker.SetNotAvailableHours(AsIndisposeds());
            return worker;
        }
开发者ID:DeStuderendesErhvervskontakt,项目名称:ProjectPlanner,代码行数:7,代码来源:CorrectWorkerSpecification.cs


示例14: Invoke

        public override void Invoke(Worker.State state)
        {
            INPUT[] queue = new INPUT[1];
            queue[0] = new INPUT();

            queue[0].type = InputType.Mouse;

            switch (button)
            {
                case MouseButtons.Left:
                    queue[0].u.Mouse.Flags |= MouseFlag.LeftUp;
                    break;
                case MouseButtons.Right:
                    queue[0].u.Mouse.Flags |= MouseFlag.RightUp;
                    break;
                case MouseButtons.Middle:
                    queue[0].u.Mouse.Flags |= MouseFlag.MiddleUp;
                    break;
                case MouseButtons.XButton1:
                    queue[0].u.Mouse.Flags |= MouseFlag.XUp;
                    queue[0].u.Mouse.MouseData |= (ushort)XButton.XButton1;
                    break;
                case MouseButtons.XButton2:
                    queue[0].u.Mouse.Flags |= MouseFlag.XUp;
                    queue[0].u.Mouse.MouseData |= (ushort)XButton.XButton2;
                    break;
            }
            NativeMethods.SendInput(1, queue, Marshal.SizeOf(typeof(INPUT)));
        }
开发者ID:pbalint,项目名称:Playground,代码行数:29,代码来源:MouseUp.cs


示例15: FormLoader

        public FormLoader(Plugin plugin, RecordReader stockReader, bool lazyLoading, int backgroundJobs)
        {
            if (backgroundJobs < 0)
                throw new ArgumentException("Number of bakcground jobs must be a positive integer or zero");

            sharedData = new SharedData()
            {
                Plugin = plugin,
                StockReader = stockReader,
                LazyLoading = lazyLoading,
                FormsToLoad = new BlockingCollection<Form>(new ConcurrentQueue<Form>(), 1024),
                WorkerCompleteEvent = new AutoResetEvent(false)
            };

            this.stockReader = stockReader;
            asyncLoading = backgroundJobs > 0;

            bool useStockReader = true;
            while (backgroundJobs-- > 0)
            {
                Worker worker = new Worker(sharedData, useStockReader);
                worker.RunWorkerCompleted += Worker_RunWorkerCompleted;
                worker.RunWorkerAsync();
                workers.Add(new WorkerInfo()
                {
                    Worker = worker
                });

                // Only the first worker can use the stock reader
                useStockReader = false;
            }
        }
开发者ID:unforbidable,项目名称:patcher,代码行数:32,代码来源:FormLoader.cs


示例16: MainServer

        public MainServer(IPEndPoint a_bindAddr_tcp1,
						  IPEndPoint a_bindAddr_tcp2,
						  IPEndPoint a_subServer_tcp,
						  IPEndPoint a_bindAddr_udp1,
						  IPEndPoint a_bindAddr_udp2,
						  IPEndPoint a_subServer_udp)
        {
            bool nullArg = a_bindAddr_tcp1 == null
                        || a_bindAddr_tcp2 == null
                        || a_subServer_tcp == null
                        || a_bindAddr_udp1 == null
                        || a_bindAddr_udp2 == null
                        || a_subServer_udp == null;
            if (nullArg)
                throw new ArgumentNullException();

            m_firstTcp = new Worker(ProtocolType.Tcp, a_bindAddr_tcp1, FirstWorkerRoutine);
            m_firstUdp = new Worker(ProtocolType.Udp, a_bindAddr_udp1, FirstWorkerRoutine);

            m_secondTcp = new Worker(ProtocolType.Tcp, a_bindAddr_tcp2, SecondWorkerRoutine);
            m_secondUdp = new Worker(ProtocolType.Udp, a_bindAddr_udp2, SecondWorkerRoutine);

            m_subServerAddr_tcp = a_subServer_tcp;
            m_subServerAddr_udp = a_subServer_udp;

            m_subServerTcp = new Worker(ProtocolType.Tcp, null, HeartbeatRoutine);
            m_subServerUdp = new Worker(ProtocolType.Udp, null, HeartbeatRoutine);
        }
开发者ID:wlsgur0726,项目名称:NAT_Test,代码行数:28,代码来源:MainServer.cs


示例17: Main

  public static int Main ()
  {
    Console.WriteLine ("Input file: ");
    string filename = Console.ReadLine ();
    int[] input;

    using (StreamReader sr = new StreamReader (filename)) {
      int noElements = Int32.Parse (sr.ReadLine ());
      input = new int[noElements];
      for (int i = 0; i < noElements; i++) {
        input [i] = Int32.Parse (sr.ReadLine ());
      }
    }

    Worker[] workers = new Worker[10];

    Thread[] threads;

    // Start the thread
    //threadx.Start ();

    // Waiting for thread to become alive
    //while (!threadx.IsAlive);

    // In miliseconds
    Thread.Sleep (1);

    // Stop threadx
    //threadx.Abort ();

    //threadx.Join ();
    return 0;
  }
开发者ID:Lukaszpg,项目名称:PP___PW_2015,代码行数:33,代码来源:Task.cs


示例18: Execute

 public void Execute(Worker worker)
 {
     if (!worker.IsOnBoard)
     {
         throw new NotImplementedException();
     }
 }
开发者ID:jauggy,项目名称:Boardgames,代码行数:7,代码来源:RemoveWorkerAction.cs


示例19: Main

    static void Main()
    {
        // load settings from App.config
        int numThreads = int.Parse(ConfigurationManager.AppSettings["numThreads"]);
        int waitTimeMillisecs = int.Parse(ConfigurationManager.AppSettings["waitTimeMillisecs"]);
        int iterations = int.Parse(ConfigurationManager.AppSettings["iterations"]);

        List<Worker> workers = new List<Worker>();

        for (int i = 0; i < numThreads; i++)
        {
            Worker worker = new Worker(iterations, waitTimeMillisecs);
            workers.Add(worker);
            ThreadStart job = new ThreadStart(worker.Run);
            Thread t = new Thread(job);
            t.Start();
        }

        long numIterations = 0;

        while (numIterations < (iterations * numThreads))
        {
            numIterations = 0;

            foreach (Worker worker in workers)
            {
                numIterations += worker.NumIterations;
            }

            Console.WriteLine("Iterations: {0}", numIterations);

            Thread.Sleep(500);
        }
    }
开发者ID:phamthanhnhan14,项目名称:corey-projects,代码行数:34,代码来源:Harness.cs


示例20: Backend

 public Backend(Exception exception, Worker worker, String queue, Object payload)
 {
     this.exception = exception;
     this.worker = worker;
     this.queue = queue;
     this.payload = payload;
 }
开发者ID:atorres757,项目名称:resque-sharp,代码行数:7,代码来源:Backend.cs



注:本文中的Worker类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# WorkerThread类代码示例发布时间:2022-05-24
下一篇:
C# Workbook类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap