private void DisposeManagedResources() { try { Stop(); // Timer var dtStart = DateTime.Now; var timeSpan = new TimeSpan(); while (IsExecute && timeSpan.TotalMilliseconds <= WaitCloseMiliSeconds) { Application.DoEvents(); Thread.Sleep(25); timeSpan = DateTime.Now - dtStart; } } catch (Exception exception) { InvokeControl.SetText(_richTextBox, @"Error DisposeManagedResources! " + Environment.NewLine + exception.Message); } finally { _objectMemorySize = null; _richTextBox = null; } }
private void StartProgress() { InvokeProgressBar.SetValue(progressBar, 0); InvokeControl.SetText(labelValue, $"{progressBar.Value} %"); while (progressBar.Value < 100) { InvokeProgressBar.SetValue(progressBar, progressBar.Value + 1); InvokeControl.SetText(labelValue, $"{progressBar.Value} %"); System.Threading.Thread.Sleep(100); } InvokeControl.SetText(labelValue, $"{progressBar.Value} %"); }
private async void buttonMoreMemory_Click(object sender, EventArgs e) { await Task.Run(() => { InvokeControl.SetText(richTextBoxMoreMemory, string.Empty); var str = string.Empty; for (var i = 1; i <= Convert.ToInt32(numericUpDown.Value * 1024); i++) { str += i + @" "; } InvokeControl.AddText(richTextBoxMoreMemory, str); }); }
public void SetText_DoesNotThrow() { Utils.MethodStart(); while (_controls.TryDequeue(out Control control)) { foreach (var value in EnumValues.GetString()) { Assert.DoesNotThrow(() => InvokeControl.SetText(control, value)); Assert.DoesNotThrowAsync(async() => await Task.Run(() => InvokeControl.SetText(control, value))); } } Utils.MethodComplete(); }
public virtual void Dispose() { lock (this) { if (!IsDisposed) { // Dispose managed resources DisposeManagedResources(); // Dispose unmanaged resources DisposeUnmanagedResources(); // Log InvokeControl.SetText(_richTextBox, @"Task memory is disposed."); // Dispose flag IsDisposed = true; } // Disable the garbage collector from calling the destructor GC.SuppressFinalize(this); } }
private void FormMain_Load(object sender, System.EventArgs e) { comboBoxProgressBarStyle.SelectedIndex = 0; InvokeControl.SetText(labelValue, $"{progressBar.Value} %"); }
public Task Execute() { return(Task.Run(() => { CheckIfDisposed(); try { var limitBytes = _objectMemorySize.Limit.Bytes; var limitMegaBytes = _objectMemorySize.Limit.GetMegaBytes(); while (IsExecute) { _objectMemorySize.Physical.Bytes = (ulong)Process.GetCurrentProcess().WorkingSet64; _objectMemorySize.Virtual.Bytes = (ulong)Process.GetCurrentProcess().PrivateMemorySize64; IsLimitOverload = !(_objectMemorySize.Physical.Bytes < limitBytes || limitBytes <= 0); if (_richTextBox != null) { InvokeControl.SetText(_richTextBox, @"Task memory ID: " + Task.CurrentId + Environment.NewLine + (limitMegaBytes <= 0 ? @"Limit memory: " + @"0 MB - is not set" : @"Limit memory: " + $"{limitMegaBytes:N0}" + @" MB - is set") + Environment.NewLine + @"Physical memory: " + $"{_objectMemorySize.Physical.GetMegaBytes():N0}" + @" MB" + Environment.NewLine + @"Virtual memory: " + $"{_objectMemorySize.Virtual.GetMegaBytes():N0}" + @" MB" + Environment.NewLine + (SimulateAction ? @"Simulate mode is enabled." : @"Simulate mode is disabled.")); } Thread.Sleep(SleepMiliSeconds); if (IsLimitOverload && !SimulateAction) { Dispose(); switch (_enumMemoryLimitAction) { case EnumMemoryLimitAction.Restart: MessageBox.Show(@"Memory limit is exceeded!" + Environment.NewLine + @"Application will be restart.", Application.ProductName); Application.Restart(); break; default: MessageBox.Show(@"Memory limit is exceeded!" + Environment.NewLine + @"Application will be exit.", Application.ProductName); Application.Exit(); break; } } } InvokeControl.SetText(_richTextBox, @"Task memory is finished."); } catch (Exception exception) { InvokeControl.SetText(_richTextBox, @"Error execute Task memory! " + Environment.NewLine + exception.Message); } finally { IsExecute = false; } })); }