当前位置: 首页>>代码示例>>C#>>正文


C# Scheduler.Close方法代码示例

本文整理汇总了C#中Scheduler.Close方法的典型用法代码示例。如果您正苦于以下问题:C# Scheduler.Close方法的具体用法?C# Scheduler.Close怎么用?C# Scheduler.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scheduler的用法示例。


在下文中一共展示了Scheduler.Close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LetsSeeIfEverythingLooksGood

        public void LetsSeeIfEverythingLooksGood()
        {
            using (Scheduler scheduler = new Scheduler())
            {

                for (int i = 0; i < 100; i++)
                {
                    //this is how to schedule a task
                    TimeSpan ts = TimeSpan.FromSeconds(random.Next(10)); // timespan in the next 10 seconds
                    object taskData = new { Title = string.Format("Do it in {0} seconds", ts.TotalSeconds) }; //task data object can be anything System.Helper.Json can handle
                    scheduler.ScheduleTask(Tasks.Todo, ts, taskData); //thread safe
                }

            }//the scheduler must be always disposed to makes sure everything was saved

            using (Scheduler scheduler = new Scheduler())
            {

                IDisposable trigger = Execute.AtInterval(TimeSpan.FromSeconds(1), x => //execute every second
                {
                    //this is how to retrive tasks
                    foreach (ScheduledTask task in scheduler.FetchScheduledItems(Tasks.Todo))
                    {
                        dynamic data = task.GetData(); // there's also a generic version: T GetData<T>()
                        string title = data.Title.ToString();

                        Trace.WriteLine(string.Format("{2} - Processed task {0} - Category: {1} ", task.Id, title, DateTime.Now.ToLongTimeString()));

                        scheduler.Close(task); //close the task (otherwise it will be executed again later)
                    }
                });

                Thread.Sleep(10000); //wait to let the timer execute incomming tasks

                trigger.Dispose(); //stops executing

            }
        }
开发者ID:raizam,项目名称:SimpleAzureScheduler,代码行数:38,代码来源:SimpleTest.cs

示例2: showRestartCommand

        private void showRestartCommand(object sender, ExecutedRoutedEventArgs e)
        {
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

            try
            {
                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

                double total = (double)dataGrid.SelectedItems.Count;
                IList drviews = dataGrid.SelectedItems;
                bool stop = false;

                for (int i = 0; i < total && !stop; i++)
                {
                    Progress p = new Progress(this, dataGrid.SelectedItems.Count, "Restarting",
                        (sndr, ea) =>
                        {
                            ProgressWorker w = (ProgressWorker)sndr;
                            Object[] args = (Object[])ea.Argument;
                            DataRowView drv = (DataRowView)drviews[i];
                            int eid = (int)drv["ID"];

                            string sharedDir = null;
                            string cluster = null;
                            string nodegroup = null;
                            string locality = null;
                            int clusterJobID = 0;
                            string executor = null;
                            string jobTemplate = null;
                            int jobTimeout = 0;
                            int taskTimeout = 0;

                            int priority = 2;
                            int min = 1, max = 100;

                            SqlCommand cmd = new SqlCommand("SELECT SharedDir, Cluster, Nodegroup, Locality, ClusterJobID, Executor, JobTemplate, JobTimeout, TaskTimeout FROM Experiments WHERE ID=" + eid + ";", sql);
                            cmd.CommandTimeout = 0;
                            SqlDataReader r = cmd.ExecuteReader();
                            while (r.Read())
                            {
                                sharedDir = (string)r[0];
                                cluster = (string)r[1];
                                nodegroup = (string)r[2];
                                locality = (string)r[3];
                                clusterJobID = (int)r[4];
                                executor = (string)r[5];
                                jobTemplate = (string)r[6];
                                jobTimeout = (int)r[7];
                                taskTimeout = (int)r[8];
                            }
                            r.Close();

                            Scheduler scheduler = new Scheduler();
                            scheduler.Connect(cluster);

                            try
                            {
                                ISchedulerJob job = scheduler.OpenJob(clusterJobID);
                                switch (job.Priority)
                                {
                                    case JobPriority.Lowest: priority = 0; break;
                                    case JobPriority.BelowNormal: priority = 1; break;
                                    case JobPriority.Normal: priority = 2; break;
                                    case JobPriority.AboveNormal: priority = 3; break;
                                    case JobPriority.Highest: priority = 4; break;
                                }

                                if (locality == "Socket")
                                {
                                    min = job.MinimumNumberOfSockets;
                                    max = job.MaximumNumberOfSockets;
                                }
                                else if (locality == "Core")
                                {
                                    min = job.MinimumNumberOfCores;
                                    max = job.MaximumNumberOfCores;
                                }
                                else if (locality == "Node")
                                {
                                    min = job.MinimumNumberOfNodes;
                                    max = job.MaximumNumberOfNodes;
                                }

                                JobState state = job.State;
                                if (state == JobState.Running || state == JobState.Queued ||
                                    state == JobState.Validating || state == JobState.Submitted ||
                                    state == JobState.ExternalValidation)
                                    scheduler.CancelJob(clusterJobID, "", true);
                            }
                            catch (SchedulerException)
                            {
                                // OK, job doesn't exist anymore.
                            }
                            catch (Exception ex)
                            {
                                Dispatcher.Invoke(new Action(() =>
                                    System.Windows.MessageBox.Show(this, "Exception: " + ex.Message, "Error",
                                                            MessageBoxButton.OK, MessageBoxImage.Error)));
                                return;
                            }
//.........这里部分代码省略.........
开发者ID:ExiaHan,项目名称:z3test,代码行数:101,代码来源:MainWindow.xaml.cs


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