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


C# Scheduler.CancelJob方法代码示例

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


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

示例1: deleteExperiment

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

            System.Windows.MessageBoxResult r =
              System.Windows.MessageBox.Show("Are you sure you want to delete the selected experiments?", "Sure?", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);

            if (r == System.Windows.MessageBoxResult.Yes)
            {
                for (int i = 0; i < dataGrid.SelectedItems.Count; i++)
                {
                    int id = (int)((DataRowView)dataGrid.SelectedItems[i])["ID"];
                    SqlDataReader rd = null;

                    try
                    {
                        SqlCommand cmd = new SqlCommand("SELECT Cluster,ClusterJobID,SharedDir,Executor FROM Experiments WHERE ID=" + id.ToString(), sql);
                        rd = cmd.ExecuteReader();

                        if (rd.Read())
                        {
                            string cluster = (string)rd["Cluster"];
                            object jobid = rd["ClusterJobID"];
                            object sharedDir = rd["SharedDir"];
                            object executor = rd["Executor"];
                            rd.Close();

                            if (cluster != "" && !DBNull.Value.Equals(jobid))
                            {
                                try
                                {
                                    Scheduler scheduler = new Scheduler();
                                    scheduler.Connect(cluster);
                                    WindowInteropHelper helper = new WindowInteropHelper(this);
                                    scheduler.SetInterfaceMode(false, helper.Handle);
                                    scheduler.CancelJob((int)jobid, "Job aborted by user.");
                                }
                                catch { /* That's fine... */ }
                            }

                            if (!DBNull.Value.Equals(sharedDir) && !DBNull.Value.Equals(executor))
                            {
                                try
                                {
                                    File.Delete((string)sharedDir + "\\" + (string)executor);
                                }
                                catch { /* That's fine... */ }
                            }

                        }

                        cmd = new SqlCommand("DELETE FROM JobQueue WHERE ExperimentID=" + id.ToString() + ";" +
                                             "DELETE FROM Data WHERE ExperimentID=" + id.ToString() + ";" +
                                             "DELETE FROM Experiments WHERE ID=" + id.ToString(), sql);
                        cmd.CommandTimeout = 0;
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        string msg = String.Format("Error: could not delete experiment #{0} because of: {1} ", id, ex.Message);
                        r = System.Windows.MessageBox.Show(msg, "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                    }
                    finally
                    {
                        if (rd != null) rd.Close();
                    }
                }
            }

            Mouse.OverrideCursor = null;

            updateDataGrid();
        }
开发者ID:ExiaHan,项目名称:z3test,代码行数:73,代码来源:MainWindow.xaml.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.CancelJob方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。