public void WindowsFormsSynchronizationContext_Dispose_MultipleTimes_Success() { var context = new WindowsFormsSynchronizationContext(); int callCount = 0; SendOrPostCallback callback = (state) => callCount++; context.Dispose(); context.Send(callback, new object()); Assert.Equal(0, callCount); // Call again. context.Dispose(); context.Send(callback, new object()); Assert.Equal(0, callCount); }
public void WindowsFormsSynchronizationContext_Send_InvokeDisposed_Nop(object state) { int callCount = 0; SendOrPostCallback callback = (actualState) => callCount++; var context = new WindowsFormsSynchronizationContext(); context.Dispose(); context.Send(callback, state); Assert.Equal(0, callCount); // Call again. context.Send(callback, state); Assert.Equal(0, callCount); }
/// <summary> /// OnPuzzleSolvedEvent /// </summary> /// <param name="steps"></param> /// <param name="time"></param> /// <param name="statesExamined"></param> private void OnPuzzleSolvedEvent(int steps, int time, int statesExamined) { Action action = () => { progressBar.Visible = false; this.Cursor = Cursors.Default; #region Progressbar kısmında bilgilendirme mesajarı yer almaktadır. if (steps > -1) { statusLabel.Text = Common.StepNumberMessage + steps.ToString("n0") + Common.TimingMessage + (time / 1000.0).ToString("n2") + Common.StepNumberMessage + statesExamined.ToString("n0"); MessageBox.Show(this, Common.SolutionFoundThereIsSeeStepCountingMessage); } else { statusLabel.Text = Common.NoStepCountOfTimingMessage + (time / 1000.0).ToString("n3") + Common.SecondOfStateMessage + statesExamined.ToString("n0"); MessageBox.Show(Common.SolutionNotFountMessage); } #endregion }; synchronizationContext.Send(item => action.Invoke(), null); }
//void process_OutputDataReceived(object sender, DataReceivedEventArgs e) //{ // //u can try play with delegate \ threds \ i gave u the tools // if (sender is Process) // { // //write your code here // //let checks if it works // } //} public void RefreshTaskListThread() // f**k lol :) { while (!_StopRefreshThread) // one of many methods to syncronize beetwen threads , reminder thread is "fire and forrget" opretion async - task! { if (listboxTasks.Items.Count != 0) { m_GuiThread.Send((object sender1) => { //sec, lets close visual and restrust? // almog always preform null and 0 checks if when u dont need , prevent bugs תודה Process maximumProcess = FindMaximumProcessMemorySize(); listboxTasks.Items.Clear(); foreach (Process process in Process.GetProcesses()) { listboxTasks.Items.Add(process.ProcessName + " | " + process.Id + " | " + process.PrivateMemorySize64 / 1000 + " kB"); // process.OutputDataReceived!!!//you seee? nice! //so this is the processes listhener? yes its called an event e.g when outdatarecived it tells everyone look what you can do for example } labelTopTask.Text = maximumProcess.ProcessName + "\n" + maximumProcess.PrivateMemorySize64 / 1000 + " kb"; labelTaskPeakNumber.Text = (maximumProcess.PeakPagedMemorySize64 / 1000).ToString() + " kb"; labelAllocatedMemoryNumber.Text = (maximumProcess.WorkingSet64 / 1000).ToString() + " kb"; }, null); //this is method to swtich beetwen Current thread to gui thread //basacily thread not built to switch but thisthe best workaround //using lambda expresions Thread.Sleep(5000); //bravo! is there a way to stop the flickring? //at the windows task manager - its refreshing without flickers or list reload. //asking from ceriosity, i gussing there orking in diffrent , you should worl with better controler than this, sometimes changiing the control is less expensive, i guessing that each proccer have a delegate(listner) to man it's change and each procces uptades by his owen ! lets check! } else { Thread.Sleep(1000); // sleep here is good desgin because it's PART of the algorthinm } } }
private void TestServer(string server) { Ping pinger = null; var delay = -1; Task.Run(() => { try { pinger = new Ping(); var reply = pinger.Send(server); var pingRelied = reply.Status == IPStatus.Success; if (pingRelied) { delay = (int)reply.RoundtripTime; } else { delay = -1; } } catch (PingException) { // Discard PingExceptions and return false; } finally { pinger?.Dispose(); } sync.Send(ShowDelay, delay); }); }
public void WindowsFormsSynchronizationContext_Send_InvokeSameThread_Success(object state) { int callCount = 0; SendOrPostCallback callback = (actualState) => { Assert.Same(state, actualState); callCount++; }; var context = new WindowsFormsSynchronizationContext(); context.Send(callback, state); Assert.Equal(1, callCount); // Call again. context.Send(callback, state); Assert.Equal(2, callCount); }
void Invoke(SendOrPostCallback d, object state, bool sync) { if (sync) { sc.Send(d, state); } else { sc.Post(d, state); } }
/// <summary> /// Shutdown all CEF instances /// </summary> internal static void Shutdown() { using (var syncObj = new WindowsFormsSynchronizationContext()) { syncObj.Send(o => { if (Cef.IsInitialized) { Cef.Shutdown(); } }, new object()); } }
public void WindowsFormsSynchronizationContext_CreateCopy_Invoke_Success() { var context = new WindowsFormsSynchronizationContext(); WindowsFormsSynchronizationContext copy = Assert.IsType <WindowsFormsSynchronizationContext>(context.CreateCopy()); Assert.NotSame(context, copy); // Send something. object state = new object(); int callCount = 0; SendOrPostCallback callback = (actualState) => { Assert.Same(state, actualState); callCount++; }; copy.Send(callback, state); Assert.Equal(1, callCount); // Call again. copy.Send(callback, state); Assert.Equal(2, callCount); }
//calcula la solucion posible private void OnPuzzleSolved(int steps, int time, int statesExamined) { Action action = () => { progressBar.Visible = false; this.Cursor = Cursors.Default; if (steps > -1) { statusLabel.Text = "Pasos: " + steps.ToString("n0") + ", Tiempo: " + (time / 1500.0).ToString("n2") + ", Estados: " + statesExamined.ToString("n0"); MessageBox.Show(this, "Se tiene una solucion..."); } else { statusLabel.Text = "Pasos: none, Tiempo: " + (time / 1500.0).ToString("n3") + "sec, Estados: " + statesExamined.ToString("n0"); MessageBox.Show(this, "Sin solución!"); } }; mSyncContext.Send(item => action.Invoke(), null); }
void mStrategy_OnPuzzleSolved(int steps, int stateExamined) { Action action = () => { this.Cursor = Cursors.Default; if (steps > -1) { mBusy = true; SetBusy(); MessageBox.Show(this, "Solution found! Click on Ok to see the steps..." + stateExamined.ToString()); } else { mBusy = false; SetBusy(); MessageBox.Show(this, "No solution found!"); } }; mSyncContext.Send(item => action.Invoke(), null); }
public override void Send(SendOrPostCallback d, object state) { baseContext.Send(d, state); }