static void ws_WorkSheetItemEnding(object sender, WorkSheetItemEndingEventArgs e) { WorkSheet ws = (sender as WorkSheet); Console.WriteLine("{0} [{1} - {2}] Ending", ws.Items[e.Index].Content, ws.Items[e.Index].BeginTime, ws.Items[e.Index].EndTime); WaitHandle.Set(); }
protected override void MainThreadFcn() { if (isUsable) { DBWIN_BUFFER_READY.Set(); } base.MainThreadFcn(); Release(); }
private void SendDirChangeToServer(object sender, ElapsedEventArgs e) { TimerDirReset(); while (eventList.Count != 0) { return; } AnalizeDir(); //say can send to server ewh.Set(); }
public void Execute(Action action) { var mtxInit = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset); lock (_lock) { _actionQueue.Enqueue(() => { action(); mtxInit.Set(); }); } _mtxWaitNewProcess.Set(); mtxInit.WaitOne(); }
static void handle_QueryISP_Command(System.Collections.Specialized.StringDictionary args) { if (args.ContainsKey("start-service")) { bool own; System.Threading.EventWaitHandle e = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset, eventName, out own); if (own) { AVIAGetPhoneSize.start(e); } else { // device monitor already started. } } else if (args.ContainsKey("kill-service")) { try { System.Threading.EventWaitHandle e = System.Threading.EventWaitHandle.OpenExisting(eventName); e.Set(); } catch (Exception) { } } }
private void executeThread() { int currentLine = CurrentLine; wantPause = false; try { status = MachineStatus.MACHINE_STATUS_RUNNING; executeEvent.Set(); executeInner(); status = MachineStatus.MACHINE_STATUS_FINISHED; } catch (BreakpointException) { status = MachineStatus.MACHINE_STATUS_PAUSED; int line = symbol_getLineByCode(pc); if (breakpointList.ContainsKey(line) && breakpointList[line] == false) { RemoveBreakpoint(line); } } catch (RuntimeException e) { status = MachineStatus.MACHINE_STATUS_DEAD; errorMessage = e.Description; } catch (Exception e) { status = MachineStatus.MACHINE_STATUS_DEAD; errorMessage = e.Message; } }
public void Init() { queue = new ConcurrentQueue <AsteroidsBL.IAsteroid>(); // Startet Task, der regelmäßig die gefilterten // Asteroiden aus einer mulithread- resistenten Queue // abruft. Task.Run(() => { AsteroidsBL.IAsteroid a; while (!queue.TryDequeue(out a)) { Debug.Write("."); System.Threading.Thread.Sleep(200); } Debug.WriteLine("1. Asteroid eingelesen"); while (!queue.TryDequeue(out a)) { Debug.Write("."); System.Threading.Thread.Sleep(200); } Debug.WriteLine("2. Asteroid eingelesen"); Ampel.Set(); }); }
static void Main(string[] args) { System.Configuration.Install.InstallContext _args = new System.Configuration.Install.InstallContext(null, args); if (_args.IsParameterTrue("start-service")) { bool own = false; System.Threading.EventWaitHandle evt = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset, NAME, out own); if (own) { // download db //Task.Run(() => download_imei2model()); start(evt); } else { // already running. } } else if (_args.IsParameterTrue("kill-service")) { try { System.Threading.EventWaitHandle evt = System.Threading.EventWaitHandle.OpenExisting(NAME); evt.Set(); } catch (Exception) { } } else { } }
private void btnSearchKey_Click(object sender, EventArgs e) { if (RedisClient == null) { DoConnection(); } try { this.treeKeys.Nodes.Clear(); System.Threading.EventWaitHandle waitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset); List <string> keys = null; new Task(() => { keys = RedisClient.SearchKeys(txtPattern.Text); waitHandle.Set(); }).Start(); if (!waitHandle.WaitOne(RedisClient.SendTimeout)) { RedisClient.Dispose(); RedisClient = null; throw new Exception("search keys timeout!"); } NestedHash keysTree = new NestedHash(); foreach (string key in keys) { string[] keySegments = key.Split(':'); NestedHash pHash = keysTree; // 指针 string pKeySegment = ""; // 指针 for (int i = 0; i < keySegments.Length; i++) { string keySegment = keySegments[i]; if (i > 0) { if (pHash[pKeySegment] == null) { NestedHash hash = new NestedHash(); pHash[pKeySegment] = hash; pHash = hash; } else { pHash = pHash[pKeySegment] as NestedHash; } } if (!pHash.ContainsKey(keySegment)) { pHash.Add(keySegment, null); } pKeySegment = keySegment; } } BuildTree(this.treeKeys.Nodes, keysTree); } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void startup(System.Collections.Specialized.StringDictionary args) { Program.logIt("OEControl::startup: ++"); if (args.ContainsKey("start")) { bool own; System.Threading.EventWaitHandle evt = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset, EVENT_NAME, out own); if (!own) { // OE app already running. Program.logIt("OEControl::startup: app already running"); } else { OEControl.OE_App_3_0_2_0(evt); } } else if (args.ContainsKey("stop")) { try { System.Threading.EventWaitHandle evt = System.Threading.EventWaitHandle.OpenExisting(EVENT_NAME); evt.Set(); } catch (Exception) { } } Program.logIt("OEControl::startup: --"); }
private void WorkerStart() { _WorkerDispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher; _WorkerDispatcher.Hooks.DispatcherInactive += WorkDone; _WorkerDispatcher.Hooks.OperationPosted += WorkAdded; _WorkerStarted.Set(); System.Windows.Threading.Dispatcher.Run(); }
public void EnqueueTask(IBrowserItem task) { lock (tasks) { tasks.Enqueue(task); wh.Set(); } }
public void RegisterDiagnosticHandler() { PublishDiagnosticsHandler diagnosticsHandler = (uri, diagList) => { diagnosticList = diagList.ToStringList(); waitHandle.Set(); }; Client.TextDocument.OnPublishDiagnostics(diagnosticsHandler); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); bool createdNew; mutex = new System.Threading.Mutex(true, Res.Resources.GetRes().GetSoftServicePCName(), out createdNew); System.Threading.EventWaitHandle eventWaitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset, Res.Resources.GetRes().GetSoftServicePCName() + Res.Resources.GetRes().GetSoftServicePCName()); if (createdNew) { // Spawn a thread which will be waiting for our event var thread = new System.Threading.Thread( () => { while (eventWaitHandle.WaitOne()) { lock (TheLock) { Form defaultForm = Application.OpenForms.Cast <Form>().Where(x => null != x.Tag && x.Tag.ToString() == "Main").FirstOrDefault(); if (null != defaultForm) { defaultForm.BeginInvoke((Action)(() => BringToForeground(defaultForm))); } } } }); // It is important mark it as background otherwise it will prevent app from exiting. thread.IsBackground = true; thread.Start(); //注册错误 Application.ThreadException += Application_ThreadException; AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); //加载日志 Resources.GetRes().LoadLog(); //字体效果(为XP开启) FontSmoothing.OpenFontEffect(); Resources.GetRes().SetDeviceType((long)1); Application.Run(new LoginWindow()); mutex.ReleaseMutex(); } // Notify other instance so it could bring itself to foreground. eventWaitHandle.Set(); // Terminate this instance. Environment.Exit(0); }
static QueueServerReceiveOption QueueServerReceiveEvent(QueueServerClient client, QueueServerMessageAckArgs args) { var t = System.Threading.Interlocked.Increment(ref total); if (t >= 1000000) { eh.Set(); } return(QueueServerReceiveOption.Nothing); }
/// <summary> /// Reset the current command to none /// </summary> /// <param name="strError"> Error message</param> public void ResetCommand(string strError) { lock (this) { CmdExecuting = CmdExecutingE.None; TimeStarted = new DateTime(0); CurrentGameIntf = null; LastCmdError = strError; Phase = 0; CmdSignal.Set(); } }
public static void ChangeHostState(String scope, String state) { try { System.Threading.EventWaitHandle evt = System.Threading.EventWaitHandle.OpenExisting(Solution.HostKillerName(scope, state)); evt.Set(); } catch (Exception) { } }
public static Task <T> ToTaskAsync <T>(this IPushObservable <T> observable) { return(Task.Run(() => { T latestValue = default(T); var mtx = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset); var disp = observable.Subscribe((v) => latestValue = v, () => mtx.Set()); mtx.WaitOne(); disp.Dispose(); return latestValue; })); }
private void LoginCheck(string result) { if (result.Equals("success")) { loginstate = true; } else { loginstate = false; } waitHandle.Set();//로그인 결과 대기 해제 }
public void PlayAsync(string url) { System.Threading.EventWaitHandle wait = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset); Task.Factory.StartNew(() => { System.Media.SoundPlayer player = new System.Media.SoundPlayer(url); player.PlaySync(); wait.Set(); }).ContinueWith(x => { wait.WaitOne(); }); }
public void method_producer() { int need = NUM_CONSUMER - Meat; Meat += need; if (need > 0) { Console.WriteLine("Add " + need + " Meat!!!"); } event_producer.Set(); System.Threading.EventWaitHandle.WaitAll(event_consumers); Sleep(); }
public Task ExecuteAsync(Action action) { var tsc = new TaskCompletionSource <object>(); lock (_lock) { _actionQueue.Enqueue(() => { try { action(); tsc.SetResult(new object()); } catch (Exception ex) { tsc.SetException(ex); } }); _mtxWaitNewProcess.Set(); } return(tsc.Task); }
/// <summary> /// Releasing locks and destroying objects /// </summary> public void Dispose() { lock (globalLock) { var item = Locks[key]; item.count--; if (item.count == 0) { Locks.Remove(key); } } ev.Set(); }
static void Main(string[] args) { System.Threading.EventWaitHandle systemweit = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset, "MeineSystemweite"); Console.WriteLine("2: Gib irgend was ein !"); Console.ReadLine(); systemweit.Set(); Console.WriteLine("2: Habe Systemweit gesetzt"); }
internal void OnRecordFinalizing(Record record) { try { // first we write the buffer mFile.InternalFillWriteBuffer(this, record); } finally { // This is one of the only place where we use Threading mechanism. // The mainthread might be waiting for it RecordFinalized.Set(); } }
public int Execute() { try { Action <string> log = text => { if (!settings.Quiet) { Console.Out.WriteLine(text); } }; var wait = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset); using (var client = new WebClientWithInfo()) { client.Headers[HttpRequestHeader.UserAgent] = settings.Http.UserAgent; client.Headers[HttpRequestHeader.Accept] = "*/*"; client.GotResponse += (object _, WebClientWithInfo.ResponseEventArgs e) => { log("Got response..."); log("Length: {0}".With(e.Response.ContentLength > -1 ? e.Response.ContentLength.ToString() : "unspecfied")); log("Saving to: '{0}'\n".With(settings.Download.OutputDocument)); }; client.DownloadProgressChanged += (object _, DownloadProgressChangedEventArgs e) => { log("progress: {0}/{1} ({2}%)".With(e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage)); }; client.DownloadDataCompleted += (_, e) => wait.Set(); settings.Urls.Each(url => { client.DownloadDataAsync(new Uri(url)); // update progressbar etc wait.WaitOne(); }); } return(0); } catch (Exception ex) { if (!settings.Quiet) { Console.Error.WriteLine(ex.Message); } return(1); } }
public override bool Execute() { System.Threading.EventWaitHandle handle = new System.Threading.EventWaitHandle( true, System.Threading.EventResetMode.AutoReset, m_Name); if (m_Lock) { handle.WaitOne(); handle.Reset(); } else { handle.Set(); } return true; }
private static void StartTaskHostService(string waitHandleId, string serviceAddress, string callBackAddress, string taskToken) { System.Threading.EventWaitHandle eventWaitHandle = System.Threading.EventWaitHandle.OpenExisting(waitHandleId); GisEditorTaskHost.Initialize(callBackAddress, taskToken); ServiceHost host = new ServiceHost(typeof(GisEditorTaskHost)); NetNamedPipeBinding binding = new NetNamedPipeBinding(); binding.ReaderQuotas.MaxStringContentLength = int.MaxValue; binding.ReceiveTimeout = TimeSpan.MaxValue; binding.MaxReceivedMessageSize = int.MaxValue; host.AddServiceEndpoint(typeof(ITaskHost), binding, serviceAddress); host.Open(); eventWaitHandle.Set(); }
public override bool Execute() { System.Threading.EventWaitHandle handle = new System.Threading.EventWaitHandle( true, System.Threading.EventResetMode.AutoReset, m_Name); if (m_Lock) { handle.WaitOne(); handle.Reset(); } else { handle.Set(); } return(true); }
public void DanglingWindowMessage() { using (OuterTest nuf = new OuterTest()) { Form f = new Form(); f.Show(); System.Threading.EventWaitHandle w = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset); System.Threading.ThreadPool.QueueUserWorkItem(delegate(object o) { f.BeginInvoke(new MethodInvoker(delegate() { MessageBox.Show("", "Blah"); })); w.Set(); }); w.WaitOne(); } }
public void DanglingWindowMessage() { using (OuterTest nuf = new OuterTest()) { Form f = new Form(); f.Show(); System.Threading.EventWaitHandle w = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset); System.Threading.ThreadPool.QueueUserWorkItem(delegate(object o) { f.BeginInvoke(new MethodInvoker(delegate() { MessageBox.Show("", "Blah"); })); w.Set(); }); w.WaitOne(); Assert.Throws<FormsTestAssertionException>(() => nuf.Verify()); } }
private bool joinBranch(Lynx.PropertySets.HFDM hfdm, Lynx.PropertySets.Workspace workspace, string branchGuid) { bool result = true; sessionLogger.Log("join branch: " + branchGuid); using (var eventWaitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset)) { hfdm.join(branchGuid, (error, repository) => { if (error != null) { System.Windows.Forms.MessageBox.Show(error.what()); sessionLogger.Log("error: " + error.what()); result = false; } else { checkoutWorkspace(workspace, branchGuid); } eventWaitHandle.Set(); }); eventWaitHandle.WaitOne(); } return(result); }
public int Execute() { try { Action<string> log = text => { if(!settings.Quiet) Console.Out.WriteLine(text); }; var wait = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset); using(var client = new WebClientWithInfo()) { client.Headers[HttpRequestHeader.UserAgent] = settings.Http.UserAgent; client.Headers[HttpRequestHeader.Accept] = "*/*"; client.GotResponse += (object _, WebClientWithInfo.ResponseEventArgs e) => { log("Got response..."); log("Length: {0}".With(e.Response.ContentLength > -1 ? e.Response.ContentLength.ToString() : "unspecfied")); log("Saving to: '{0}'\n".With(settings.Download.OutputDocument)); }; client.DownloadProgressChanged += (object _, DownloadProgressChangedEventArgs e) => { log("progress: {0}/{1} ({2}%)".With(e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage)); }; client.DownloadDataCompleted += (_, e) => wait.Set(); settings.Urls.Each(url => { client.DownloadDataAsync(new Uri(url)); // update progressbar etc wait.WaitOne(); }); } return 0; } catch (Exception ex) { if(!settings.Quiet) Console.Error.WriteLine(ex.Message); return 1; } }
/// <summary>Creates and then sets the specified event.</summary> /// <param name="eventName">Name of the event.</param> public static void SetEvent(string eventName) { _eventWaitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset, eventName); _eventWaitHandle.Set(); }