コード例 #1
0
    public void StartRemoteJob()
    {
        string error;

        _checkInputFile      = false;
        _theTabs.SelectedTab = _tabLog;
        _log.Text            = "";

        Interlocked.Increment(ref Scheduler.numNetJobsRunning);
        //_houston.SetStatusBarText(Scheduler.numJobsRunning.ToString());

        _job = null;
        _net = new SfbClient(this);
        SetSubItem(Display.cpu, "0.0s");
        SetSubItem(Display.mem, "0kb");
        if ((error = _net.Connect(remotehost, remoteport, filetype)) == null)
        {
            string requiredversion = "";

            if (filetype == FileType.sfbox && _net.ServerVersionIsAtLeast(requiredversion = "0.5") || (filetype == FileType.mcrenko || filetype == FileType.ctb) && _net.ServerVersionIsAtLeast(requiredversion = "0.7"))
            {
                this._houston.AddtoRegistry(remotehost, remoteport);

                ArrayList news = _net.GetNews();

                string shortName = _net.SendInputFile(FullName);

                if (filetype == FileType.mcrenko)
                {
                    RemoteCompileMC(_net);
                }

                SetStartTime(DateTime.Now);
                SetStatus(Status.running);

                RunDelegate   run             = new RunDelegate(RunAndDownload);
                AsyncCallback myAsyncCallback = new AsyncCallback(NetHasExited);
                run.BeginInvoke(_net, shortName, DirectoryName, this, myAsyncCallback, null);

                PopupMessages(news);
            }
            else
            {
                SetStatus(Status.aborted);
                MessageBox.Show("You need at least server version " + requiredversion + " for what you are trying to do.", "Server error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Interlocked.Decrement(ref Scheduler.numNetJobsRunning);
            }
        }
        else
        {
            SetStatus(Status.aborted);
            MessageBox.Show("Server connection error:\n\n" + error, "Server error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            _log.AppendText("\r\nCould not connect: " + error);
            Interlocked.Decrement(ref Scheduler.numNetJobsRunning);
            //_houston.SetStatusBarText(Scheduler.numJobsRunning.ToString());
        }
    }
コード例 #2
0
        //开始异步运行
        public IAsyncResult BeginRun(AsyncCallback asyncCallBack, object stateObject)
        {
            Console.WriteLine("【1】BeginRun excuting");
            //_runDelegate.BeginInvoke(asyncCallBack, stateObject);
            for (var i = 1; i < 3; i++)
            {
                Console.WriteLine("Runing...");
                Thread.Sleep(1000);
            }

            return(_runDelegate.BeginInvoke(asyncCallBack, stateObject));;
        }
コード例 #3
0
  public static void Main(){
		RunDelegate runDelegate1 = new RunDelegate(Run);
		RunDelegate runDelegate2 = new RunDelegate(Run);
		IAsyncResult result1 = runDelegate1.BeginInvoke("Hello", null, null);
		IAsyncResult result2 = runDelegate2.BeginInvoke("World!", null, null);
		while(!(result1.IsCompleted && result2.IsCompleted)){
			Console.Write(" - ");
			Thread.Sleep(1000);
		}
		runDelegate1.EndInvoke(result1);
		runDelegate2.EndInvoke(result2);
		Console.WriteLine("\nMain thread exiting now...bye!");
  } // end Main() method
コード例 #4
0
        public void Run()
        {
            if (Plan.PositionLogs == null || Plan.PositionLogs.Count == 0)
            {
                _log.LogError(Plan.Id, "There are no positions to execute the forecast");
                throw new ForecastServiceException("There are no positions to execute the forecast");
            }
            if (Plan.GetStatus() == ForecastPlanStatus.Running)
            {
                _log.LogWarning(Plan.Id, "Already Running");
                throw new ForecastServiceException("Already Running");
            }
            _dataService.DeleteResults(Plan.Id);
            Plan.SetStatus(ForecastPlanStatus.Running);
            _dataService.UpdateForecastPlan(Plan);
            //_dataService.DeleteResults(Plan.Id);
            var runDelegate = new RunDelegate(ExecutePositions);

            runDelegate.BeginInvoke(RunCallback, runDelegate);
        }