/// <summary>
        /// Sample the image intensity one time, awaitable for the result, or hook to event
        /// </summary>
        /// <returns>intensity result (Task awaitable)</returns>
        public async Task <double> Trigger()
        {
            double intensity = await _cam.GetIntensity();

            ResultReady?.Invoke(this, new ResultEventArgs(intensity));
            return(intensity);
        }
Example #2
0
        private async Task AquireMandelbrotSet()
        {
            using (var server = new Server(Host, Port))
            {
                var request = new Request(
                    _random.Next(),
                    CenterX,
                    CenterY,
                    DistanceX,
                    DistanceY,
                    Resolution,
                    MaxIterations,
                    Threshold
                    );
                try
                {
                    await server.SendRequest(request);

                    _cachedData = await server.ReceiveResult();
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                    Debugger.Break();
                }

                ResultReady?.Invoke(this, EventArgs.Empty);
            }
        }
Example #3
0
 public void Sqrt(int a)
 {
     Task.Run(() =>
     {
         Console.WriteLine($"Called Sqrt({a}) on thread {Thread.CurrentThread.ManagedThreadId}");
         var result = _calculator.Sqrt(a);
         ResultReady?.Invoke(Thread.CurrentThread.ManagedThreadId.ToString(), new OperationResult(result));
     });
 }
Example #4
0
 /// <summary>
 /// Constructor of the class <see cref="Requestor"/>
 /// </summary>
 /// <param name="uri">URI of the Raspberry Pi to connect to (such as "http://xxx.xxx.xxx.xxx")</param>
 /// <param name="resultReadyCallback">Function of type <see cref="ResultReady"/>, called when a new result is received</param>
 public Requestor(string uri, int requestPeriod, ResultReady resultReadyCallback = null)
 {
     Uri           = uri;
     RequestPeriod = requestPeriod;
     Result        = default;
     RequestWorker = new BackgroundWorker {
         WorkerSupportsCancellation = true
     };
     RequestWorker.DoWork += new DoWorkEventHandler(RequestWorker_DoWork);
     ResultReadyCallback   = resultReadyCallback;
 }
 public TaskAgent(Func <string, string> task, string input)
 {
     this.task  = task;
     this.input = input;
     this.timer = new Timer()
     {
         AutoReset = true, Interval = 1000
     };
     this.timer.Enabled  = false;
     this.timer.Elapsed += (s, e) =>
     {
         var result = task(input);
         ResultReady?.Invoke(this, result);
     };
 }
Example #6
0
        /// <summary>
        /// The worker thread that processes items in the results queue.
        /// </summary>
        private void WriteResults()
        {
            try
            {
                //WorkIsExpected will be set to false when the Engine finishes its Foreach loop.
                while (WorkIsExpected)
                {
                    //Wait for limited period of time to be notified of results being ready. This may be too short for long running operations.
                    ResultReady.WaitOne(new TimeSpan(0, 0, 10));

                    //If a result can be retrieved from the queue, write the results to file.
                    while (Results.TryDequeue(out ISearch result))
                    {
                        WriteResultAsync(result);
                    }
                }
            }
            finally
            {
                //Always dispose of the output file to release locks.
                OutputFile.Dispose();
            }
        }
        private async void buttonAnalyze_Click(object sender, EventArgs e)
        {
            SetAlgoPatternFromUI();
            if (!m_pattern.Contains("1"))
            {
                MessageBox.Show("Please select at least one column to display!", "Error"); //icon
                return;
            }

            List <TypeOfAlgo> neededTypes = new List <TypeOfAlgo>();

            for (int i = 0; i < m_pattern.Length; i++)
            {
                if (m_pattern[i] == '1')
                {
                    neededTypes.Add((TypeOfAlgo)i);
                }
            }

            progressBar.Visible   = true;
            buttonAnalyze.Enabled = false;

            await Task.Factory.StartNew(() =>
            {
                List <Tuple <TypeOfAlgo, double> > resultList = Analyzer.Analyze(neededTypes,
                                                                                 (int)numericUpDownA.Value, (int)numericUpDownB.Value, (int)numericUpDownP.Value, //a, b, p bytes
                                                                                 (int)numericNumRuns.Value);                                                      //number of runs

                DataTable dt = ToDataTable(resultList);

                ResultReady?.Invoke(dt);
            });

            progressBar.Visible   = false;
            buttonAnalyze.Enabled = true;
        }
Example #8
0
 /// <summary>
 /// Recieves results as an ISearch object. The results are added to the queue and ResultReady is notified.
 /// </summary>
 /// <param name="result">The result which will be stored.</param>
 internal void RecieveResult(ISearch result)
 {
     Results.Enqueue(result);
     ResultReady.Set();
 }
 private void OnResultReady(FileMoveResult result)
 {
     ResultReady?.Invoke(typeof(Desktop), result);
 }