private void bt4_Click(object sender, EventArgs e) { b = new StringBuilder(); ThreadStart ts = new ThreadStart(t1Start); IAsyncResult r1 = ts.BeginInvoke(null, null); IAsyncResult r2 = ts.BeginInvoke(null, null); ts.EndInvoke(r1); ts.EndInvoke(r2); tbOut.Text = b.ToString(); }
public void Dispose() { if (_locked) { _locked = false; _complete.Set(); _delegate.EndInvoke(_async); } }
private void CompleteAsync() { var completion = _asyncWriteBehind; if (completion != null && !completion.IsCompleted) { _asyncWriteBehind = null; _writeBehindFunc.EndInvoke(completion); } }
public ThreadedWriter(ILockStrategy lck) { _started = new ManualResetEvent(false); _complete = new ManualResetEvent(false); _lck = lck; _delegate = HoldLock; _async = _delegate.BeginInvoke(null, null); if (!_started.WaitOne(1000, false)) { _delegate.EndInvoke(_async); Assert.Fail("Unable to acquire lock"); } Assert.IsTrue(_locked); }
public void GenerateCGImagesAsynchronously_Compat() { handled = false; mre = new ManualResetEvent(false); ThreadStart main = () => { using (NSUrl video_url = NSUrl.FromFilename(video_asset_path)) using (AVAsset video_asset = AVAsset.FromUrl(video_url)) using (AVAssetImageGenerator aig = new AVAssetImageGenerator(video_asset)) { aig.GenerateCGImagesAsynchronously(NSValue.FromCMTime(CMTime.Zero), handler); mre.WaitOne(); } }; var asyncResult = main.BeginInvoke(null, null); main.EndInvoke(asyncResult); Assert.True(mre.WaitOne(2000)); Assert.True(handled, "handled"); }
public void GenerateCGImagesAsynchronously() { // This test deadlocks on Mountain Lion (but works on Lion) // https://gist.github.com/rolfbjarne/1190d97af79e554c298f2c133dfd8e87 TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 9, throwIfOtherPlatform: false); handled = false; mre = new ManualResetEvent(false); ThreadStart main = () => { using (NSUrl video_url = NSUrl.FromFilename(video_asset_path)) using (AVAsset video_asset = AVAsset.FromUrl(video_url)) using (AVAssetImageGenerator aig = new AVAssetImageGenerator(video_asset)) { NSValue[] values = new NSValue[] { NSValue.FromCMTime(CMTime.Zero) }; aig.GenerateCGImagesAsynchronously(values, handler); mre.WaitOne(); } }; var asyncResult = main.BeginInvoke(null, null); main.EndInvoke(asyncResult); Assert.True(mre.WaitOne(2000), "wait"); Assert.True(handled, "handled"); }
void AsyncFinished(IAsyncResult ar) { ThreadStart async = ar.AsyncState as ThreadStart; async.EndInvoke(ar); }
/// <summary> /// Unitest will cal this one /// </summary> /// <param name="batchId"></param> /// <returns></returns> public bool ExecuteOneBatch(string batchId) { try { var jp = new JsonParser(); //VSH: clean global configuration before ExecuteOneBatch Boolean res = jp.AddConfigToMemory(""); string remote = Constants.MemoryConf["RemoteNode"]; int timeoutAllScenarios = Convert.ToInt32(Constants.MemoryConf["TimeoutAllScenarios"]) * 1000; var sel = new Selenium(); if (batchId == string.Empty) { MessageBox.Show("Select Batch first", "Applenium"); return(false); } var sql = new Sql(); _batchId = Convert.ToInt32(batchId); DataTable dtScenario = sql.GetDataTable(Constants.StrBatchScenariosToSelenium, _batchId.ToString(CultureInfo.InvariantCulture)); //SetAllScenariusStatusToRunorNot(dtScenario, Constants.Pending); var adapterBatches = new BatchesTableAdapter(); var adapterBatchLogic = new BatchLogicTableAdapter(); var adapterBrowser = new BrowsersTableAdapter(); _batchname = adapterBatches.GetBatchName(_batchId); var adapterScenario = new ScenarioTableAdapter(); _projectId = Convert.ToInt32(adapterBatches.GetProjectID(Convert.ToInt32(_batchId))); LogObject logObject = new LogObject(); logObject.ExecutionID = _runExecutionId; logObject.BatchID = _batchId; logObject.Description = Constants.LogBatchStatus + "=" + Constants.PROGRESS_STARTED; logObject.BatchName = _batchname; logObject.BatchProgress = Constants.PROGRESS_STARTED; logObject.StatusTag = Constants.DONE; logObject.ProjectID = _projectId; logger.Print(logObject); Singleton myInstance = Singleton.Instance; myInstance.BatchResult = true; var threadFinishEvents = new List <EventWaitHandle>(); foreach (DataRow row in dtScenario.Rows) { if (myInstance.StopExecution) { myInstance.BatchResult = false; break; } var threadFinish = new EventWaitHandle(false, EventResetMode.ManualReset); string BrowserID = row["BrowserID"].ToString(); string batchLogicId = row["BatchLogicID"].ToString(); int executionStatus = Convert.ToInt32(row["ExecutionStatusID"].ToString()); if (executionStatus == 1) //run only selected scenarios { threadFinishEvents.Add(threadFinish); _browserName = adapterBrowser.GetBrowserName(Convert.ToInt32(BrowserID)); ThreadStart ts = delegate { //wait till hub return available browser RemoteWebDriver driver = null; driver = sel.SetWebDriverBrowser(null, BrowserID, false); driver.Manage().Window.Maximize(); string scenarioId = row["ScenarioID"].ToString(); // adapterBatchLogic.Update(_batchId, Convert.ToInt32(scenarioId), Convert.ToInt32(browserId),Constants.Running, Convert.ToInt32(batchLogicId)); string scenarioname = adapterScenario.GetScenarioName(Convert.ToInt32(scenarioId)); if (guiInstance != null && isBatchRun == true) { guiInstance.UpdateProgressLabel("", "", Constants.UpdateProgress_REGULAR); } LogObject logObject2 = new LogObject(); logObject2.ExecutionID = _runExecutionId; logObject2.BatchID = _batchId; logObject2.ScenarioID = Convert.ToInt32(scenarioId); logObject2.ScnearioName = scenarioname; logObject2.Browser = _browserName; logObject2.ProjectID = _projectId; logObject2.ProjectName = _projectName; logObject2.BatchName = _batchname; logObject2.ProjectPageID = _projectPageId; logObject2.StatusTag = Constants.DONE; logObject2.Browser = _browserName; logger.Print(logObject2); // Do long work here bool scanearioresult = ExecuteOneScenario(scenarioId, driver); Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, (EventHandler) delegate { if (scanearioresult == false) { myInstance.BatchResult = false; //adapterBatchLogic.Update(_batchId,Convert.ToInt32(scenarioId),Convert.ToInt32(browserId),Constants.Failed,Convert.ToInt32(batchLogicId)); } driver.Quit(); threadFinish.Set(); }, null, null); }; try { ts.BeginInvoke(delegate(IAsyncResult aysncResult) { ts.EndInvoke(aysncResult); }, null); } catch (Exception exc) { MessageBox.Show("An exception has occoured when trying to execute a scenario - " + exc.TargetSite); } if (remote == "no") { WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios)); } } } WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios)); string description; int status; string bStatus = Constants.PROGRESS_FAILED; if (myInstance.BatchResult) { description = string.Format("{0}={1}", Constants.LogBatchName, "Passed"); status = Constants.PASSED; bStatus = Constants.PROGRESS_PASSED; //LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Passed",Constants.Passed, "0", _projectId, 0); } else { //LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Failed",Constants.Failed, "0", _projectId, 0); description = string.Format("{0}={1}", Constants.LogBatchStatus, "Failed"); status = Constants.FAILED; bStatus = Constants.PROGRESS_FAILED; } LogObject logObject3 = new LogObject(); logObject3.ExecutionID = _runExecutionId; logObject3.BatchID = Convert.ToInt32(_batchId); logObject3.Description = description; logObject3.StatusTag = status; logObject3.BatchStatus = bStatus; logObject3.ProjectID = _projectId; logger.Print(logObject3); //SetAllScenariusStatusToRunorNot(dtScenario, Constants.NotRunnig); return(myInstance.BatchResult); } catch (Exception exception) { LogObject exceptionLog = new LogObject(); exceptionLog.Description = exception.Message; exceptionLog.StatusTag = Constants.ERROR; logger.Print(exceptionLog); return(false); } }
/// <summary> /// Unitest will cal this one /// </summary> /// <param name="batchId"></param> /// <returns></returns> public bool ExecuteOneBatch(string batchId) { try { var jp = new JsonParser(); string remote = jp.ReadJson("RemoteNode"); int timeoutAllScenarios = Convert.ToInt32(jp.ReadJson("TimeoutAllScenarios")) * 1000; var sel = new Selenium(); if (batchId == string.Empty) { MessageBox.Show("Select Batch first", "Applenium"); return(false); } var sql = new Sql(); _batchId = Convert.ToInt32(batchId); DataTable dtScenario = sql.GetDataTable(Constants.StrBatchScenariosToSelenium, _batchId.ToString(CultureInfo.InvariantCulture)); //SetAllScenariusStatusToRunorNot(dtScenario, Constants.Pending); var adapterBatches = new BatchesTableAdapter(); var adapterBatchLogic = new BatchLogicTableAdapter(); var adapterBrowser = new BrowsersTableAdapter(); string batchname = adapterBatches.GetBatchName(_batchId); var adapterScenario = new ScenarioTableAdapter(); _projectId = Convert.ToInt32(adapterBatches.GetProjectID(Convert.ToInt32(_batchId))); LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, Constants.LogBatchStatus + "=Started", Constants.Done, "0", _projectId, 0); Singleton myInstance = Singleton.Instance; myInstance.BatchResult = true; var threadFinishEvents = new List <EventWaitHandle>(); foreach (DataRow row in dtScenario.Rows) { if (myInstance.StopExecution) { myInstance.BatchResult = false; break; } var threadFinish = new EventWaitHandle(false, EventResetMode.ManualReset); string browserId = row["BrowserID"].ToString(); string batchLogicId = row["BatchLogicID"].ToString(); int executionStatus = Convert.ToInt32(row["ExecutionStatusID"].ToString()); if (executionStatus == 1) //run only selected scenarios { threadFinishEvents.Add(threadFinish); string browserName = adapterBrowser.GetBrowserName(Convert.ToInt32(browserId)); ThreadStart ts = delegate { //wait till hub return available browser RemoteWebDriver driver = null; int elapsed = 0; while ((driver == null) && (elapsed < timeoutAllScenarios)) { //generate random number 30-60 Random r = new Random(); int rInt = r.Next(30000, 60000); //for ints Thread.Sleep(rInt); driver = sel.SetWebDriverBrowser(null, browserId, false); elapsed += rInt; } string scenarioId = row["ScenarioID"].ToString(); // adapterBatchLogic.Update(_batchId, Convert.ToInt32(scenarioId), Convert.ToInt32(browserId),Constants.Running, Convert.ToInt32(batchLogicId)); string scenarioname = adapterScenario.GetScenarioName(Convert.ToInt32(scenarioId)); if (guiInstance != null && isBatchRun == true) { guiInstance.UpdateProgressLabel(scenarioname); } LogResult(_runExecutionId, Convert.ToInt32(_batchId), Convert.ToInt32(scenarioId), 0, 0, scenarioname + " ScenarioBrowser=" + browserName, Constants.Done, "0", _projectId, _projectPageId); // Do long work here bool scanearioresult = ExecuteOneScenario(scenarioId, driver); Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, (EventHandler) delegate { if (scanearioresult == false) { myInstance.BatchResult = false; //adapterBatchLogic.Update(_batchId,Convert.ToInt32(scenarioId),Convert.ToInt32(browserId),Constants.Failed,Convert.ToInt32(batchLogicId)); } driver.Quit(); threadFinish.Set(); }, null, null); }; ts.BeginInvoke(delegate(IAsyncResult aysncResult) { ts.EndInvoke(aysncResult); }, null); if (remote == "no") { WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios)); } } } WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios)); string description; int status; if (myInstance.BatchResult) { description = string.Format("{0}={1}", Constants.LogBatchName, "Passed"); status = Constants.Passed; //LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Passed",Constants.Passed, "0", _projectId, 0); } else { //LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Failed",Constants.Failed, "0", _projectId, 0); description = string.Format("{0}={1}", Constants.LogBatchStatus, "Failed"); status = Constants.Failed; } LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, description, status, "0", _projectId, 0); //SetAllScenariusStatusToRunorNot(dtScenario, Constants.NotRunnig); return(myInstance.BatchResult); } catch (Exception exception) { Logger.Error(exception.Message, exception); return(false); } }
/// <summary> /// Unitest will cal this one /// </summary> /// <param name="batchId"></param> /// <returns></returns> public bool ExecuteOneBatch(string batchId) { var jp = new JsonParser(); string remote = jp.ReadJson("RemoteNode"); int timeoutAllScenarios = Convert.ToInt32(jp.ReadJson("TimeoutAllScenarios")) * 1000; var sel = new Selenium(); if (batchId == string.Empty) { MessageBox.Show("Select Batch first", "Applenium"); return(false); } var sql = new Sql(); _batchId = Convert.ToInt32(batchId); DataTable dtScenario = sql.GetDataTable(Constants.StrBatchScenariosToSelenium, _batchId.ToString(CultureInfo.InvariantCulture)); SetAllScenariusStatusToRunorNot(dtScenario, Constants.Pending); var adapterBatches = new BatchesTableAdapter(); var adapterBatchLogic = new BatchLogicTableAdapter(); var adapterBrowser = new BrowsersTableAdapter(); string batchname = adapterBatches.GetBatchName(_batchId); var adapterScenario = new ScenarioTableAdapter(); _projectId = Convert.ToInt32(adapterBatches.GetProjectID(Convert.ToInt32(_batchId))); LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Started", Constants.Done, "0", _projectId, 0); Singleton myInstance = Singleton.Instance; myInstance.BatchResult = true; var threadFinishEvents = new List <EventWaitHandle>(); foreach (DataRow row in dtScenario.Rows) { if (myInstance.StopExecution) { myInstance.BatchResult = false; break; } var threadFinish = new EventWaitHandle(false, EventResetMode.ManualReset); threadFinishEvents.Add(threadFinish); string browserId = row["BrowserID"].ToString(); string batchLogicId = row["BatchLogicID"].ToString(); string browserName = adapterBrowser.GetBrowserName(Convert.ToInt32(browserId)); IWebDriver driver = null; ThreadStart ts = delegate { driver = sel.SetWebDriverBrowser(driver, browserId, false); if (driver == null) { return; } string scenarioId = row["ScenarioID"].ToString(); adapterBatchLogic.Update(_batchId, Convert.ToInt32(scenarioId), Convert.ToInt32(browserId), Constants.Running, Convert.ToInt32(batchLogicId)); string scenarioname = adapterScenario.GetScenarioName(Convert.ToInt32(scenarioId)); LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, scenarioname + " Scenario will run on " + browserName + " browser.", Constants.Done, "0", _projectId, 0); // Do long work here bool scanearioresult = ExecuteOneScenario(scenarioId, driver); Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, (EventHandler) delegate { if (scanearioresult == false) { myInstance.BatchResult = false; adapterBatchLogic.Update(_batchId, Convert.ToInt32(scenarioId), Convert.ToInt32(browserId), Constants.Failed, Convert.ToInt32(batchLogicId)); } else { adapterBatchLogic.Update(_batchId, Convert.ToInt32(scenarioId), Convert.ToInt32(browserId), Constants.Passed, Convert.ToInt32(batchLogicId)); } driver.Quit(); threadFinish.Set(); }, null, null); }; ts.BeginInvoke(delegate(IAsyncResult aysncResult) { ts.EndInvoke(aysncResult); }, null); if (remote == "no") { WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios)); } } WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios)); if (myInstance.BatchResult) { LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Passed", Constants.Passed, "0", _projectId, 0); } else { LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Failed", Constants.Failed, "0", _projectId, 0); //LogFailiure(_runExecutionID, 0, null, 0, null, "Description in the scenario"); } SetAllScenariusStatusToRunorNot(dtScenario, Constants.NotRunnig); return(myInstance.BatchResult); }