public bool AddFile() { if (HttpContext.Request.Form.Files.Count == 0) { return(false); } var s = HttpContext.Request.Form.Files[0]; if (s != null) { string id = Guid.NewGuid().ToString(); string path = "clientapp/FileIN/" + id; using (var fileStream = new FileStream(path, FileMode.Create)) { s.CopyTo(fileStream); } WrapperProcessor wrapperProcessor = new WrapperProcessor() { Id = id }; wrapperProcessor.Task = new Task(wrapperProcessor.startProcess); wrapperProcessor.Task.Start(); processList.Add(wrapperProcessor); HttpContext.Response.Cookies.Append("id", id, new CookieOptions() { }); return(true); } return(false); }
private void StartGrindingButton_OnClick(object sender, RoutedEventArgs e) { StartGrindingButton.IsEnabled = false; m_processingCts = new CancellationTokenSource(); m_processingToken = m_processingCts.Token; m_primes = new ConcurrentBag <int>(); Task.Factory.StartNew( () => { m_stopwatch = Stopwatch.StartNew(); m_managedCalls = 0; m_nativeCalls = 0; Parallel.For( 0, Int32.MaxValue, new ParallelOptions { CancellationToken = m_processingToken }, n => { if (ThreadSafeRandom.Next() % 2 == 0) { Interlocked.Increment(ref m_managedCalls); if (ManagedProcessor.IsPrime(n)) { m_primes.Add(n); } } else { Interlocked.Increment(ref m_nativeCalls); if (WrapperProcessor.IsPrime(n)) { m_primes.Add(n); } } }); }, m_processingToken); m_stopwatch.Stop(); }