示例#1
0
        // TODO: Implement a percentage done feedback in the future?

        /// <summary>
        /// Query the manager to determine if a job with the unique job handle provided is done or not. The server returns
        /// a "percentage" done, if that's 100%, then the job is complete. This is mainly used for background jobs, in case
        /// the progress needs to be reported.
        /// </summary>
        /// <param name="jobHandle">
        /// A <see cref="System.String"/> containing the unique job ID to query
        /// </param>
        /// <returns>
        /// True if complete, False otherwise
        /// </returns>
        public bool checkIsDone(string jobHandle)
        {
            GetStatus statusPkt = new GetStatus(jobHandle);

            Packet result = null;

            foreach (Connection conn in managers)
            {
                Log.DebugFormat("Checking for status on {0} on {1}", jobHandle, conn);
                conn.sendPacket(statusPkt);

                result = conn.getNextPacket();

                if (result.Type == PacketType.STATUS_RES)
                {
                    StatusRes statusResult = (StatusRes)result;

                    if (statusResult.jobhandle != jobHandle)
                    {
                        Log.DebugFormat("Wrong job!!");
                    }
                    else
                    {
                        Log.DebugFormat("Hooray, this is my job!!");

                        float percentdone = 0;

                        if (statusResult.pctCompleteDenominator != 0)
                        {
                            percentdone = statusResult.pctCompleteNumerator / statusResult.pctCompleteDenominator;
                        }


                        // Check to see if this response has a known status
                        // and if it's running

                        if (statusResult.knownstatus && statusResult.running)
                        {
                            Log.DebugFormat("{0}% done!", percentdone * 100);
                        }
                        else
                        {
                            if (!statusResult.knownstatus)
                            {
                                Log.DebugFormat("Status of job not known!");
                            }

                            if (!statusResult.running)
                            {
                                Log.DebugFormat("Job not running!");
                            }
                        }

                        return(percentdone == 1);
                    }
                }
            }

            return(false);
        }
示例#2
0
        static void Main(string[] args)
        {
start:
            Console.Clear();
            Process[] pc = Process.GetProcesses();
            foreach (var item in pc)
            {
                try
                {
                    if (item.ProcessName == "svchost")
                    {
                        continue;
                    }
                    Console.WriteLine("{0}\t{1}", item.ProcessName, item.Id);
                }
                catch { continue; }
            }

            while (true)
            {
                string id  = Console.ReadLine();
                int    pid = -1;
                int.TryParse(id, out pid);
                try
                {
                    Process   obj = Process.GetProcessById(pid);
                    StatusRes r   = ckeckUser();
                    if (r == StatusRes.Y)
                    {
                        obj.Kill();
                    }
                }
                catch {  }
                goto start;
            }
        }