Minor performance optimization

This commit is contained in:
Nikolaj Olsson 2024-11-20 19:15:37 +01:00
parent c1754a0343
commit 800f01cc65
13 changed files with 74 additions and 69 deletions

View File

@ -11,6 +11,7 @@ using System.Runtime.CompilerServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Nikse.SubtitleEdit.Core.Forms; using Nikse.SubtitleEdit.Core.Forms;
using System.Diagnostics;
namespace Nikse.SubtitleEdit.Controls namespace Nikse.SubtitleEdit.Controls
{ {
@ -486,7 +487,7 @@ namespace Nikse.SubtitleEdit.Controls
public void SetPosition(double startPositionSeconds, Subtitle subtitle, double currentVideoPositionSeconds, int subtitleIndex, ListView.SelectedIndexCollection selectedIndexes) public void SetPosition(double startPositionSeconds, Subtitle subtitle, double currentVideoPositionSeconds, int subtitleIndex, ListView.SelectedIndexCollection selectedIndexes)
{ {
if (TimeSpan.FromTicks(DateTime.UtcNow.Ticks - _lastMouseWheelScroll).TotalSeconds > 0.25) if (TimeSpan.FromTicks(Stopwatch.GetTimestamp() - _lastMouseWheelScroll).TotalSeconds > 0.25)
{ // don't set start position when scrolling with mouse wheel as it will make a bad (jumping back) forward scrolling { // don't set start position when scrolling with mouse wheel as it will make a bad (jumping back) forward scrolling
StartPositionSeconds = startPositionSeconds; StartPositionSeconds = startPositionSeconds;
} }
@ -1195,7 +1196,7 @@ namespace Nikse.SubtitleEdit.Controls
_firstMove = true; _firstMove = true;
if (e.Button == MouseButtons.Left) if (e.Button == MouseButtons.Left)
{ {
_buttonDownTimeTicks = DateTime.UtcNow.Ticks; _buttonDownTimeTicks = Stopwatch.GetTimestamp();
Cursor = Cursors.VSplit; Cursor = Cursors.VSplit;
double seconds = RelativeXPositionToSeconds(e.X); double seconds = RelativeXPositionToSeconds(e.X);
@ -2086,7 +2087,7 @@ namespace Nikse.SubtitleEdit.Controls
if (e.Button == MouseButtons.Left && OnSingleClick != null) if (e.Button == MouseButtons.Left && OnSingleClick != null)
{ {
var diff = Math.Abs(_mouseMoveStartX - e.X); var diff = Math.Abs(_mouseMoveStartX - e.X);
if (_mouseMoveStartX == -1 || _mouseMoveEndX == -1 || diff < 10 && TimeSpan.FromTicks(DateTime.UtcNow.Ticks - _buttonDownTimeTicks).TotalSeconds < 0.25) if (_mouseMoveStartX == -1 || _mouseMoveEndX == -1 || diff < 10 && TimeSpan.FromTicks(Stopwatch.GetTimestamp() - _buttonDownTimeTicks).TotalSeconds < 0.25)
{ {
if (ModifierKeys == Keys.Shift && SelectedParagraph != null) if (ModifierKeys == Keys.Shift && SelectedParagraph != null)
{ {
@ -2326,7 +2327,7 @@ namespace Nikse.SubtitleEdit.Controls
else else
{ {
StartPositionSeconds += delta / 256.0; StartPositionSeconds += delta / 256.0;
_lastMouseWheelScroll = DateTime.UtcNow.Ticks; _lastMouseWheelScroll = Stopwatch.GetTimestamp();
if (_currentVideoPositionSeconds < _startPositionSeconds || _currentVideoPositionSeconds >= EndPositionSeconds) if (_currentVideoPositionSeconds < _startPositionSeconds || _currentVideoPositionSeconds >= EndPositionSeconds)
{ {
OnPositionSelected?.Invoke(this, new ParagraphEventArgs(_startPositionSeconds, null)); OnPositionSelected?.Invoke(this, new ParagraphEventArgs(_startPositionSeconds, null));

View File

@ -1,6 +1,7 @@
using Nikse.SubtitleEdit.Core.Common; using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Logic; using Nikse.SubtitleEdit.Logic;
using System; using System;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
@ -30,7 +31,7 @@ namespace Nikse.SubtitleEdit.Controls
KeyDown += SETextBox_KeyDown; KeyDown += SETextBox_KeyDown;
// To fix issue where WM_LBUTTONDOWN got wrong "SelectedText" (only in undocked mode) // To fix issue where WM_LBUTTONDOWN got wrong "SelectedText" (only in undocked mode)
GotFocus += (sender, args) => { _gotFocusTicks = DateTime.UtcNow.Ticks; }; GotFocus += (sender, args) => { _gotFocusTicks = Stopwatch.GetTimestamp(); };
} }
private void SetAlignment() private void SetAlignment()
@ -208,7 +209,7 @@ namespace Nikse.SubtitleEdit.Controls
if (_dragFromThis) if (_dragFromThis)
{ {
_dragFromThis = false; _dragFromThis = false;
var milliseconds = (DateTime.UtcNow.Ticks - _dragStartTicks) / 10000; var milliseconds = (Stopwatch.GetTimestamp() - _dragStartTicks) / 10000;
if (milliseconds < 400) if (milliseconds < 400)
{ {
SelectionLength = 0; SelectionLength = 0;
@ -337,12 +338,12 @@ namespace Nikse.SubtitleEdit.Controls
if (m.Msg == WM_LBUTTONDOWN) if (m.Msg == WM_LBUTTONDOWN)
{ {
var milliseconds = (DateTime.UtcNow.Ticks - _gotFocusTicks) / 10000; var milliseconds = (Stopwatch.GetTimestamp() - _gotFocusTicks) / 10000;
if (milliseconds > 10) if (milliseconds > 10)
{ {
_dragText = SelectedText; _dragText = SelectedText;
_dragStartFrom = SelectionStart; _dragStartFrom = SelectionStart;
_dragStartTicks = DateTime.UtcNow.Ticks; _dragStartTicks = Stopwatch.GetTimestamp();
} }
} }

View File

@ -326,7 +326,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
var buffer = new byte[4096]; var buffer = new byte[4096];
_bytesWavTotal = new FileInfo(waveFileName).Length; _bytesWavTotal = new FileInfo(waveFileName).Length;
_bytesWavRead = 0; _bytesWavRead = 0;
_startTicks = DateTime.UtcNow.Ticks; _startTicks = Stopwatch.GetTimestamp();
timer1.Start(); timer1.Start();
using (var source = File.OpenRead(waveFileName)) using (var source = File.OpenRead(waveFileName))
{ {
@ -605,7 +605,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
return; return;
} }
var durationMs = (DateTime.UtcNow.Ticks - _startTicks) / 10_000; var durationMs = (Stopwatch.GetTimestamp() - _startTicks) / 10_000;
var msPerFrame = (float)durationMs / _bytesWavRead; var msPerFrame = (float)durationMs / _bytesWavRead;
var estimatedTotalMs = msPerFrame * _bytesWavTotal; var estimatedTotalMs = msPerFrame * _bytesWavTotal;
var estimatedLeft = ProgressHelper.ToProgressTime(estimatedTotalMs - durationMs); var estimatedLeft = ProgressHelper.ToProgressTime(estimatedTotalMs - durationMs);

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -227,7 +228,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
var buffer = new byte[4096]; var buffer = new byte[4096];
_bytesWavTotal = new FileInfo(waveFileName).Length; _bytesWavTotal = new FileInfo(waveFileName).Length;
_bytesWavRead = 0; _bytesWavRead = 0;
_startTicks = DateTime.UtcNow.Ticks; _startTicks = Stopwatch.GetTimestamp();
timer1.Start(); timer1.Start();
using (var source = File.OpenRead(waveFileName)) using (var source = File.OpenRead(waveFileName))
{ {
@ -325,7 +326,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
return; return;
} }
var durationMs = (DateTime.UtcNow.Ticks - _startTicks) / 10_000; var durationMs = (Stopwatch.GetTimestamp() - _startTicks) / 10_000;
var msPerFrame = (float)durationMs / _bytesWavRead; var msPerFrame = (float)durationMs / _bytesWavRead;
var estimatedTotalMs = msPerFrame * _bytesWavTotal; var estimatedTotalMs = msPerFrame * _bytesWavTotal;
var estimatedLeft = ProgressHelper.ToProgressTime(estimatedTotalMs - durationMs); var estimatedLeft = ProgressHelper.ToProgressTime(estimatedTotalMs - durationMs);

View File

@ -929,7 +929,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
var process = GetWhisperProcess(inputFile, model.Name, _languageCode, checkBoxTranslateToEnglish.Checked, OutputHandler); var process = GetWhisperProcess(inputFile, model.Name, _languageCode, checkBoxTranslateToEnglish.Checked, OutputHandler);
var sw = Stopwatch.StartNew(); var sw = Stopwatch.StartNew();
_outputText.Add($"Calling whisper ({Configuration.Settings.Tools.WhisperChoice}) with : {process.StartInfo.FileName} {process.StartInfo.Arguments}{Environment.NewLine}"); _outputText.Add($"Calling whisper ({Configuration.Settings.Tools.WhisperChoice}) with : {process.StartInfo.FileName} {process.StartInfo.Arguments}{Environment.NewLine}");
_startTicks = DateTime.UtcNow.Ticks; _startTicks = Stopwatch.GetTimestamp();
_videoInfo = UiUtil.GetVideoInfo(waveFileName); _videoInfo = UiUtil.GetVideoInfo(waveFileName);
timer1.Start(); timer1.Start();
if (!_batchMode) if (!_batchMode)
@ -1573,7 +1573,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
return; return;
} }
var durationMs = (DateTime.UtcNow.Ticks - _startTicks) / 10_000; var durationMs = (Stopwatch.GetTimestamp() - _startTicks) / 10_000;
labelElapsed.Text = new TimeCode(durationMs).ToShortDisplayString(); labelElapsed.Text = new TimeCode(durationMs).ToShortDisplayString();
if (_endSeconds <= 0 || _videoInfo == null) if (_endSeconds <= 0 || _videoInfo == null)

View File

@ -802,7 +802,7 @@ namespace Nikse.SubtitleEdit.Forms
process.Start(); process.Start();
process.BeginOutputReadLine(); process.BeginOutputReadLine();
process.BeginErrorReadLine(); process.BeginErrorReadLine();
_startTicks = DateTime.UtcNow.Ticks; _startTicks = Stopwatch.GetTimestamp();
timer1.Start(); timer1.Start();
while (!process.HasExited) while (!process.HasExited)
@ -855,7 +855,7 @@ namespace Nikse.SubtitleEdit.Forms
return; return;
} }
var durationMs = (DateTime.UtcNow.Ticks - _startTicks) / 10_000; var durationMs = (Stopwatch.GetTimestamp() - _startTicks) / 10_000;
var msPerFrame = (float)durationMs / _processedFrames; var msPerFrame = (float)durationMs / _processedFrames;
var estimatedTotalMs = msPerFrame * _totalFrames; var estimatedTotalMs = msPerFrame * _totalFrames;
var estimatedLeft = ProgressHelper.ToProgressTime(estimatedTotalMs - durationMs); var estimatedLeft = ProgressHelper.ToProgressTime(estimatedTotalMs - durationMs);

View File

@ -199,7 +199,7 @@ namespace Nikse.SubtitleEdit.Forms
process.BeginErrorReadLine(); process.BeginErrorReadLine();
_totalFrames = (long)Math.Round(float.Parse(comboBoxFrameRate.Text, CultureInfo.CurrentCulture) * (float)numericUpDownDurationMinutes.Value * 60.0f); _totalFrames = (long)Math.Round(float.Parse(comboBoxFrameRate.Text, CultureInfo.CurrentCulture) * (float)numericUpDownDurationMinutes.Value * 60.0f);
progressBar1.Maximum = (int)_totalFrames; progressBar1.Maximum = (int)_totalFrames;
_startTicks = DateTime.UtcNow.Ticks; _startTicks = Stopwatch.GetTimestamp();
timer1.Start(); timer1.Start();
while (!process.HasExited) while (!process.HasExited)
{ {
@ -314,7 +314,7 @@ namespace Nikse.SubtitleEdit.Forms
return; return;
} }
var durationMs = (DateTime.UtcNow.Ticks - _startTicks) / 10_000; var durationMs = (Stopwatch.GetTimestamp() - _startTicks) / 10_000;
var msPerFrame = (float)durationMs / _processedFrames; var msPerFrame = (float)durationMs / _processedFrames;
var estimatedTotalMs = msPerFrame * _totalFrames; var estimatedTotalMs = msPerFrame * _totalFrames;
var estimatedLeft = ProgressHelper.ToProgressTime(estimatedTotalMs - durationMs); var estimatedLeft = ProgressHelper.ToProgressTime(estimatedTotalMs - durationMs);

View File

@ -935,7 +935,7 @@ namespace Nikse.SubtitleEdit.Forms
process.Start(); process.Start();
process.BeginOutputReadLine(); process.BeginOutputReadLine();
process.BeginErrorReadLine(); process.BeginErrorReadLine();
_startTicks = DateTime.UtcNow.Ticks; _startTicks = Stopwatch.GetTimestamp();
timer1.Start(); timer1.Start();
while (!process.HasExited) while (!process.HasExited)
@ -965,7 +965,7 @@ namespace Nikse.SubtitleEdit.Forms
process.Start(); process.Start();
process.BeginOutputReadLine(); process.BeginOutputReadLine();
process.BeginErrorReadLine(); process.BeginErrorReadLine();
_startTicks = DateTime.UtcNow.Ticks; _startTicks = Stopwatch.GetTimestamp();
timer1.Start(); timer1.Start();
while (!process.HasExited) while (!process.HasExited)
@ -1054,7 +1054,7 @@ namespace Nikse.SubtitleEdit.Forms
process.Start(); process.Start();
process.BeginOutputReadLine(); process.BeginOutputReadLine();
process.BeginErrorReadLine(); process.BeginErrorReadLine();
_startTicks = DateTime.UtcNow.Ticks; _startTicks = Stopwatch.GetTimestamp();
timer1.Start(); timer1.Start();
while (!process.HasExited) while (!process.HasExited)
@ -1185,7 +1185,7 @@ namespace Nikse.SubtitleEdit.Forms
return; return;
} }
var durationMs = (DateTime.UtcNow.Ticks - _startTicks) / 10_000; var durationMs = (Stopwatch.GetTimestamp() - _startTicks) / 10_000;
var msPerFrame = (float)durationMs / _processedFrames; var msPerFrame = (float)durationMs / _processedFrames;
var estimatedTotalMs = msPerFrame * _totalFrames; var estimatedTotalMs = msPerFrame * _totalFrames;
var estimatedLeft = ProgressHelper.ToProgressTime(estimatedTotalMs - durationMs); var estimatedLeft = ProgressHelper.ToProgressTime(estimatedTotalMs - durationMs);

View File

@ -2456,7 +2456,7 @@ namespace Nikse.SubtitleEdit.Forms
private void AutoSave(bool force = false) private void AutoSave(bool force = false)
{ {
if (!Configuration.Settings.General.AutoSave || if (!Configuration.Settings.General.AutoSave ||
DateTime.UtcNow.Ticks - _lastAutoSave < 10000 * 3000 && !force) // only check for auto save evety 3 seconds Stopwatch.GetTimestamp() - _lastAutoSave < 10000 * 3000 && !force) // only check for auto save evety 3 seconds
{ {
return; return;
} }
@ -2476,7 +2476,7 @@ namespace Nikse.SubtitleEdit.Forms
private void DoAutoSave() private void DoAutoSave()
{ {
_lastAutoSave = DateTime.UtcNow.Ticks + 1009000; _lastAutoSave = Stopwatch.GetTimestamp() + 1009000;
var currentSubtitleHash = GetFastSubtitleHash(); var currentSubtitleHash = GetFastSubtitleHash();
if (_changeSubtitleHash != currentSubtitleHash && _lastDoNotPrompt != currentSubtitleHash && _subtitle?.Paragraphs.Count > 0) if (_changeSubtitleHash != currentSubtitleHash && _lastDoNotPrompt != currentSubtitleHash && _subtitle?.Paragraphs.Count > 0)
{ {
@ -2493,7 +2493,7 @@ namespace Nikse.SubtitleEdit.Forms
SaveOriginalSubtitle(GetCurrentSubtitleFormat(), true); SaveOriginalSubtitle(GetCurrentSubtitleFormat(), true);
} }
_lastAutoSave = DateTime.UtcNow.Ticks; _lastAutoSave = Stopwatch.GetTimestamp();
} }
private bool ContinueNewOrExit() private bool ContinueNewOrExit()
@ -2672,10 +2672,10 @@ namespace Nikse.SubtitleEdit.Forms
return; return;
} }
if ((DateTime.UtcNow.Ticks - _lastHistoryTicks) > 10000 * 500) // only if last change was longer ago than 500 milliseconds if ((Stopwatch.GetTimestamp() - _lastHistoryTicks) > 10000 * 500) // only if last change was longer ago than 500 milliseconds
{ {
MakeHistoryForUndo(description); MakeHistoryForUndo(description);
_lastHistoryTicks = DateTime.UtcNow.Ticks; _lastHistoryTicks = Stopwatch.GetTimestamp();
} }
} }
@ -2887,7 +2887,7 @@ namespace Nikse.SubtitleEdit.Forms
return; return;
} }
_lastAutoSave = DateTime.UtcNow.Ticks; _lastAutoSave = Stopwatch.GetTimestamp();
bool videoFileLoaded = false; bool videoFileLoaded = false;
_formatManuallyChanged = false; _formatManuallyChanged = false;
var file = new FileInfo(fileName); var file = new FileInfo(fileName);
@ -6499,7 +6499,7 @@ namespace Nikse.SubtitleEdit.Forms
ShowSourceLineNumber(); ShowSourceLineNumber();
_sourceViewChange = true; _sourceViewChange = true;
labelStatus.Text = string.Empty; labelStatus.Text = string.Empty;
_sourceTextTicks = DateTime.UtcNow.Ticks; _sourceTextTicks = Stopwatch.GetTimestamp();
} }
private bool ShowProfileInStatusBar => Configuration.Settings.General.CurrentProfile != "Default"; private bool ShowProfileInStatusBar => Configuration.Settings.General.CurrentProfile != "Default";
@ -11513,7 +11513,7 @@ namespace Nikse.SubtitleEdit.Forms
private void TextBoxListViewTextKeyDown(object sender, KeyEventArgs e) private void TextBoxListViewTextKeyDown(object sender, KeyEventArgs e)
{ {
_listViewTextTicks = DateTime.UtcNow.Ticks; _listViewTextTicks = Stopwatch.GetTimestamp();
if (e.Modifiers == Keys.Shift && e.KeyCode == Keys.ShiftKey) if (e.Modifiers == Keys.Shift && e.KeyCode == Keys.ShiftKey)
{ {
@ -11810,7 +11810,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
// last key down in text // last key down in text
_lastTextKeyDownTicks = DateTime.UtcNow.Ticks; _lastTextKeyDownTicks = Stopwatch.GetTimestamp();
UpdatePositionAndTotalLength(labelTextLineTotal, textBoxListViewText); UpdatePositionAndTotalLength(labelTextLineTotal, textBoxListViewText);
} }
@ -15205,7 +15205,7 @@ namespace Nikse.SubtitleEdit.Forms
ShowStatus(string.Format("{0}, {1:0}%", statusMessage, _lastProgressPercent)); ShowStatus(string.Format("{0}, {1:0}%", statusMessage, _lastProgressPercent));
statusStrip1.Refresh(); statusStrip1.Refresh();
TaskbarList.SetProgressValue(Handle, percent, 100); TaskbarList.SetProgressValue(Handle, percent, 100);
if (DateTime.UtcNow.Ticks % 10 == 0) if (Stopwatch.GetTimestamp() % 10 == 0)
{ {
Application.DoEvents(); Application.DoEvents();
} }
@ -16952,15 +16952,15 @@ namespace Nikse.SubtitleEdit.Forms
{ {
if (e.KeyCode == Keys.LWin) if (e.KeyCode == Keys.LWin)
{ {
_winLeftDownTicks = DateTime.UtcNow.Ticks; _winLeftDownTicks = Stopwatch.GetTimestamp();
} }
if (e.KeyCode == Keys.RWin) if (e.KeyCode == Keys.RWin)
{ {
_winRightDownTicks = DateTime.UtcNow.Ticks; _winRightDownTicks = Stopwatch.GetTimestamp();
} }
if ((DateTime.UtcNow.Ticks - _winLeftDownTicks) <= 10000 * 999 || (DateTime.UtcNow.Ticks - _winRightDownTicks) <= 10000 * 999) // less than 999 ms if ((Stopwatch.GetTimestamp() - _winLeftDownTicks) <= 10000 * 999 || (Stopwatch.GetTimestamp() - _winRightDownTicks) <= 10000 * 999) // less than 999 ms
{ {
// if it's less than one second since Win key was pressed we ignore key (not perfect...) // if it's less than one second since Win key was pressed we ignore key (not perfect...)
e.SuppressKeyPress = true; e.SuppressKeyPress = true;
@ -18398,7 +18398,7 @@ namespace Nikse.SubtitleEdit.Forms
mediaPlayer.CurrentPosition = startSeconds; mediaPlayer.CurrentPosition = startSeconds;
UiUtil.ShowSubtitle(_subtitle, mediaPlayer, GetCurrentSubtitleFormat()); UiUtil.ShowSubtitle(_subtitle, mediaPlayer, GetCurrentSubtitleFormat());
mediaPlayer.Play(); mediaPlayer.Play();
_endSecondsNewPositionTicks = DateTime.UtcNow.Ticks; _endSecondsNewPositionTicks = Stopwatch.GetTimestamp();
} }
e.SuppressKeyPress = true; e.SuppressKeyPress = true;
@ -18414,7 +18414,7 @@ namespace Nikse.SubtitleEdit.Forms
mediaPlayer.CurrentPosition = startSeconds; mediaPlayer.CurrentPosition = startSeconds;
UiUtil.ShowSubtitle(_subtitle, mediaPlayer, GetCurrentSubtitleFormat()); UiUtil.ShowSubtitle(_subtitle, mediaPlayer, GetCurrentSubtitleFormat());
mediaPlayer.Play(); mediaPlayer.Play();
_endSecondsNewPositionTicks = DateTime.UtcNow.Ticks; _endSecondsNewPositionTicks = Stopwatch.GetTimestamp();
} }
e.SuppressKeyPress = true; e.SuppressKeyPress = true;
@ -21033,7 +21033,7 @@ namespace Nikse.SubtitleEdit.Forms
labelNextWord.Text = string.Format(_language.NextX, HtmlUtil.RemoveHtmlTags(next.Text, true).Replace(Environment.NewLine, " ")); labelNextWord.Text = string.Format(_language.NextX, HtmlUtil.RemoveHtmlTags(next.Text, true).Replace(Environment.NewLine, " "));
labelNextWord.Left = audioVisualizer.Width / 2 - labelNextWord.Width / 2 + audioVisualizer.Left; labelNextWord.Left = audioVisualizer.Width / 2 - labelNextWord.Width / 2 + audioVisualizer.Left;
labelNextWord.Visible = true; labelNextWord.Visible = true;
_labelNextTicks = DateTime.UtcNow.Ticks; _labelNextTicks = Stopwatch.GetTimestamp();
} }
else else
{ {
@ -21231,7 +21231,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
_textHeightResize = splitContainerListViewAndText.Height - splitContainerListViewAndText.SplitterDistance; _textHeightResize = splitContainerListViewAndText.Height - splitContainerListViewAndText.SplitterDistance;
_textHeightResizeIgnoreUpdate = DateTime.UtcNow.Ticks; _textHeightResizeIgnoreUpdate = Stopwatch.GetTimestamp();
mediaPlayer.ShowFullScreenControls(); mediaPlayer.ShowFullScreenControls();
bool setRedockOnFullscreenEnd = false; bool setRedockOnFullscreenEnd = false;
@ -24183,7 +24183,7 @@ namespace Nikse.SubtitleEdit.Forms
int index = ShowSubtitle(); int index = ShowSubtitle();
if (index != -1 && oldIndex != index && checkBoxSyncListViewWithVideoWhilePlaying.Checked) if (index != -1 && oldIndex != index && checkBoxSyncListViewWithVideoWhilePlaying.Checked)
{ {
if ((DateTime.UtcNow.Ticks - _lastTextKeyDownTicks) > 10000 * 700) // only if last typed char was entered > 700 milliseconds if ((Stopwatch.GetTimestamp() - _lastTextKeyDownTicks) > 10000 * 700) // only if last typed char was entered > 700 milliseconds
{ {
if (_endSeconds <= 0 || !checkBoxAutoRepeatOn.Checked) if (_endSeconds <= 0 || !checkBoxAutoRepeatOn.Checked)
{ {
@ -24205,7 +24205,7 @@ namespace Nikse.SubtitleEdit.Forms
mediaPlayer.Pause(); mediaPlayer.Pause();
if (_playSelectionIndex < 0) if (_playSelectionIndex < 0)
{ {
if (_endSecondsNewPosition >= 0 && _endSecondsNewPositionTicks > DateTime.UtcNow.Ticks - (10000 * 900)) // 900 ms if (_endSecondsNewPosition >= 0 && _endSecondsNewPositionTicks > Stopwatch.GetTimestamp() - (10000 * 900)) // 900 ms
{ {
mediaPlayer.CurrentPosition = _endSecondsNewPosition; mediaPlayer.CurrentPosition = _endSecondsNewPosition;
} }
@ -24329,7 +24329,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
if (labelNextWord.Visible && _labelNextTicks + 100000000 < DateTime.UtcNow.Ticks) if (labelNextWord.Visible && _labelNextTicks + 100000000 < Stopwatch.GetTimestamp())
{ {
labelNextWord.Visible = false; labelNextWord.Visible = false;
} }
@ -24367,7 +24367,7 @@ namespace Nikse.SubtitleEdit.Forms
Text = Text.RemoveChar('*').TrimEnd(); Text = Text.RemoveChar('*').TrimEnd();
} }
if (InSourceView && _sourceTextTicks != -1 && (DateTime.UtcNow.Ticks - _sourceTextTicks) > 10000 * 700) // only if last typed char was entered > 700 milliseconds if (InSourceView && _sourceTextTicks != -1 && (Stopwatch.GetTimestamp() - _sourceTextTicks) > 10000 * 700) // only if last typed char was entered > 700 milliseconds
{ {
ReloadFromSourceInSourceView(); ReloadFromSourceInSourceView();
_sourceTextTicks = -1; _sourceTextTicks = -1;
@ -24651,7 +24651,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
} }
_textHeightResizeIgnoreUpdate = DateTime.UtcNow.Ticks; _textHeightResizeIgnoreUpdate = Stopwatch.GetTimestamp();
SubtitleListview1.AutoSizeAllColumns(this); SubtitleListview1.AutoSizeAllColumns(this);
if (WindowState == FormWindowState.Maximized || if (WindowState == FormWindowState.Maximized ||
@ -24684,7 +24684,7 @@ namespace Nikse.SubtitleEdit.Forms
private void Main_ResizeBegin(object sender, EventArgs e) private void Main_ResizeBegin(object sender, EventArgs e)
{ {
_textHeightResizeIgnoreUpdate = DateTime.UtcNow.Ticks; _textHeightResizeIgnoreUpdate = Stopwatch.GetTimestamp();
if (_loading) if (_loading)
{ {
return; return;
@ -25697,7 +25697,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
timerAutoContinue.Stop(); timerAutoContinue.Stop();
if ((DateTime.UtcNow.Ticks - _lastTextKeyDownTicks) > 10000 * 700) // only if last typed char was entered > 700 milliseconds if ((Stopwatch.GetTimestamp() - _lastTextKeyDownTicks) > 10000 * 700) // only if last typed char was entered > 700 milliseconds
{ {
labelStatus.Text = string.Empty; labelStatus.Text = string.Empty;
PlayNext(); PlayNext();
@ -26343,7 +26343,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
try try
{ {
_textHeightResizeIgnoreUpdate = DateTime.UtcNow.Ticks; _textHeightResizeIgnoreUpdate = Stopwatch.GetTimestamp();
_textHeightResize = splitContainerListViewAndText.Height - splitContainerListViewAndText.SplitterDistance; _textHeightResize = splitContainerListViewAndText.Height - splitContainerListViewAndText.SplitterDistance;
} }
catch catch
@ -26411,7 +26411,7 @@ namespace Nikse.SubtitleEdit.Forms
SubtitleListview1.Focus(); SubtitleListview1.Focus();
} }
_lastTextKeyDownTicks = DateTime.UtcNow.Ticks; _lastTextKeyDownTicks = Stopwatch.GetTimestamp();
if (_subtitleOriginal != null && _subtitleOriginal.Paragraphs.Count > 0) if (_subtitleOriginal != null && _subtitleOriginal.Paragraphs.Count > 0)
{ {
var idx = _subtitleListViewIndex; var idx = _subtitleListViewIndex;
@ -29732,7 +29732,7 @@ namespace Nikse.SubtitleEdit.Forms
return; return;
} }
_textHeightResizeIgnoreUpdate = DateTime.UtcNow.Ticks; _textHeightResizeIgnoreUpdate = Stopwatch.GetTimestamp();
mediaPlayer.ShowNonFullScreenControls(); mediaPlayer.ShowNonFullScreenControls();
SaveUndockedPositions(); SaveUndockedPositions();
@ -30091,7 +30091,7 @@ namespace Nikse.SubtitleEdit.Forms
private void TextBoxListViewTextOriginalKeyDown(object sender, KeyEventArgs e) private void TextBoxListViewTextOriginalKeyDown(object sender, KeyEventArgs e)
{ {
_listViewOriginalTextTicks = DateTime.UtcNow.Ticks; _listViewOriginalTextTicks = Stopwatch.GetTimestamp();
if (_subtitleOriginal == null || _subtitleOriginal.Paragraphs.Count < 1) if (_subtitleOriginal == null || _subtitleOriginal.Paragraphs.Count < 1)
{ {
return; return;
@ -30283,7 +30283,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
// last key down in text // last key down in text
_lastTextKeyDownTicks = DateTime.UtcNow.Ticks; _lastTextKeyDownTicks = Stopwatch.GetTimestamp();
UpdatePositionAndTotalLength(labelTextOriginalLineTotal, textBoxListViewTextOriginal); UpdatePositionAndTotalLength(labelTextOriginalLineTotal, textBoxListViewTextOriginal);
} }
@ -31619,7 +31619,7 @@ namespace Nikse.SubtitleEdit.Forms
return; return;
} }
if ((DateTime.UtcNow.Ticks - _listViewTextTicks) > 10000 * 700) // only if last typed char was entered > 700 milliseconds if ((Stopwatch.GetTimestamp() - _listViewTextTicks) > 10000 * 700) // only if last typed char was entered > 700 milliseconds
{ {
var p = _subtitle.GetParagraphOrDefault(index); var p = _subtitle.GetParagraphOrDefault(index);
if (p == null) if (p == null)
@ -31713,7 +31713,7 @@ namespace Nikse.SubtitleEdit.Forms
return; return;
} }
if ((DateTime.UtcNow.Ticks - _listViewOriginalTextTicks) > 10000 * 700) // only if last typed char was entered > 700 milliseconds if ((Stopwatch.GetTimestamp() - _listViewOriginalTextTicks) > 10000 * 700) // only if last typed char was entered > 700 milliseconds
{ {
var original = Utilities.GetOriginalParagraph(index, _subtitle.Paragraphs[index], _subtitleOriginal.Paragraphs); var original = Utilities.GetOriginalParagraph(index, _subtitle.Paragraphs[index], _subtitleOriginal.Paragraphs);
if (original != null) if (original != null)
@ -34207,7 +34207,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
if (Configuration.Settings.VideoControls.WaveformFocusOnMouseEnter && audioVisualizer.WavePeaks != null && !audioVisualizer.Focused && audioVisualizer.CanFocus) if (Configuration.Settings.VideoControls.WaveformFocusOnMouseEnter && audioVisualizer.WavePeaks != null && !audioVisualizer.Focused && audioVisualizer.CanFocus)
{ {
if (Math.Abs(_lastWaveformMenuCloseTicks - DateTime.UtcNow.Ticks) > 10000 * 500) // only if last change was longer ago than 500 milliseconds if (Math.Abs(_lastWaveformMenuCloseTicks - Stopwatch.GetTimestamp()) > 10000 * 500) // only if last change was longer ago than 500 milliseconds
{ {
audioVisualizer.Focus(); audioVisualizer.Focus();
} }
@ -34529,7 +34529,7 @@ namespace Nikse.SubtitleEdit.Forms
private void ContextMenuStripWaveformClosing(object sender, ToolStripDropDownClosingEventArgs e) private void ContextMenuStripWaveformClosing(object sender, ToolStripDropDownClosingEventArgs e)
{ {
_lastWaveformMenuCloseTicks = DateTime.UtcNow.Ticks; _lastWaveformMenuCloseTicks = Stopwatch.GetTimestamp();
} }
private void MenuOpened(object sender, EventArgs e) private void MenuOpened(object sender, EventArgs e)
@ -35603,7 +35603,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
} }
var diff = DateTime.UtcNow.Ticks - _textHeightResizeIgnoreUpdate; var diff = Stopwatch.GetTimestamp() - _textHeightResizeIgnoreUpdate;
if (diff > 10_000 * 750 && // 750 ms if (diff > 10_000 * 750 && // 750 ms
WindowState == _lastFormWindowState) WindowState == _lastFormWindowState)
{ {
@ -35818,7 +35818,7 @@ namespace Nikse.SubtitleEdit.Forms
private void SplitContainerMainSplitterMoving(object sender, SplitterCancelEventArgs e) private void SplitContainerMainSplitterMoving(object sender, SplitterCancelEventArgs e)
{ {
_textHeightResizeIgnoreUpdate = DateTime.UtcNow.Ticks; _textHeightResizeIgnoreUpdate = Stopwatch.GetTimestamp();
} }
private void ApplyCustomStylesToolStripMenuItemClick(object sender, EventArgs e) private void ApplyCustomStylesToolStripMenuItemClick(object sender, EventArgs e)

View File

@ -32,6 +32,7 @@ using Nikse.SubtitleEdit.Core.Settings;
using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox; using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox;
using Timer = System.Windows.Forms.Timer; using Timer = System.Windows.Forms.Timer;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Diagnostics;
namespace Nikse.SubtitleEdit.Forms.Ocr namespace Nikse.SubtitleEdit.Forms.Ocr
{ {
@ -6645,7 +6646,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{ {
if (subtitleListView1.SelectedItems.Count > 1) if (subtitleListView1.SelectedItems.Count > 1)
{ {
if (DateTime.UtcNow.Ticks - _slvSelIdxChangedTicks < 100000) if (Stopwatch.GetTimestamp() - _slvSelIdxChangedTicks < 100000)
{ {
_slvSelIdx = new KeyValuePair<long, int>(_slvSelIdxChangedTicks, subtitleListView1.SelectedItems[0].Index); _slvSelIdx = new KeyValuePair<long, int>(_slvSelIdxChangedTicks, subtitleListView1.SelectedItems[0].Index);
if (_changeDelayTimer == null) if (_changeDelayTimer == null)
@ -6659,10 +6660,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
_changeDelayTimer.Stop(); _changeDelayTimer.Stop();
_changeDelayTimer.Start(); _changeDelayTimer.Start();
} }
_slvSelIdxChangedTicks = DateTime.UtcNow.Ticks; _slvSelIdxChangedTicks = Stopwatch.GetTimestamp();
return; return;
} }
_slvSelIdxChangedTicks = DateTime.UtcNow.Ticks; _slvSelIdxChangedTicks = Stopwatch.GetTimestamp();
} }
_selectedIndex = subtitleListView1.SelectedItems[0].Index; _selectedIndex = subtitleListView1.SelectedItems[0].Index;
} }

View File

@ -3,6 +3,7 @@ using Nikse.SubtitleEdit.Core.Dictionaries;
using Nikse.SubtitleEdit.Logic; using Nikse.SubtitleEdit.Logic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -694,7 +695,7 @@ namespace Nikse.SubtitleEdit.Forms.Options
e.SuppressKeyPress = true; e.SuppressKeyPress = true;
if (TimeSpan.FromTicks(_listBoxSearchStringLastUsed.Ticks).TotalMilliseconds + 1800 < if (TimeSpan.FromTicks(_listBoxSearchStringLastUsed.Ticks).TotalMilliseconds + 1800 <
TimeSpan.FromTicks(DateTime.UtcNow.Ticks).TotalMilliseconds) TimeSpan.FromTicks(Stopwatch.GetTimestamp()).TotalMilliseconds)
{ {
_listBoxSearchString = string.Empty; _listBoxSearchString = string.Empty;
} }
@ -866,7 +867,7 @@ namespace Nikse.SubtitleEdit.Forms.Options
e.SuppressKeyPress = true; e.SuppressKeyPress = true;
if (TimeSpan.FromTicks(_listBoxSearchStringLastUsed.Ticks).TotalMilliseconds + 1800 < if (TimeSpan.FromTicks(_listBoxSearchStringLastUsed.Ticks).TotalMilliseconds + 1800 <
TimeSpan.FromTicks(DateTime.UtcNow.Ticks).TotalMilliseconds) TimeSpan.FromTicks(Stopwatch.GetTimestamp()).TotalMilliseconds)
{ {
_listBoxSearchString = string.Empty; _listBoxSearchString = string.Empty;
} }
@ -902,7 +903,7 @@ namespace Nikse.SubtitleEdit.Forms.Options
e.SuppressKeyPress = true; e.SuppressKeyPress = true;
if (TimeSpan.FromTicks(_listBoxSearchStringLastUsed.Ticks).TotalMilliseconds + 1800 < if (TimeSpan.FromTicks(_listBoxSearchStringLastUsed.Ticks).TotalMilliseconds + 1800 <
TimeSpan.FromTicks(DateTime.UtcNow.Ticks).TotalMilliseconds) TimeSpan.FromTicks(Stopwatch.GetTimestamp()).TotalMilliseconds)
{ {
_listBoxSearchString = string.Empty; _listBoxSearchString = string.Empty;
} }

View File

@ -67,7 +67,7 @@ namespace Nikse.SubtitleEdit.Logic
return LibMpvDynamic.GetVideoInfo(fileName); return LibMpvDynamic.GetVideoInfo(fileName);
} }
private static long _lastShowSubTicks = DateTime.UtcNow.Ticks; private static long _lastShowSubTicks = Stopwatch.GetTimestamp();
private static int _lastShowSubHash; private static int _lastShowSubHash;
public static int ShowSubtitle(Subtitle subtitle, VideoPlayerContainer videoPlayerContainer, SubtitleFormat format) public static int ShowSubtitle(Subtitle subtitle, VideoPlayerContainer videoPlayerContainer, SubtitleFormat format)
@ -115,7 +115,7 @@ namespace Nikse.SubtitleEdit.Logic
private static void TimeOutRefresh(Subtitle subtitle, VideoPlayerContainer videoPlayerContainer, SubtitleFormat format, Paragraph p = null) private static void TimeOutRefresh(Subtitle subtitle, VideoPlayerContainer videoPlayerContainer, SubtitleFormat format, Paragraph p = null)
{ {
if (DateTime.UtcNow.Ticks - _lastShowSubTicks > 10000 * 1000) // more than 1+ seconds ago if (Stopwatch.GetTimestamp() - _lastShowSubTicks > 10000 * 1000) // more than 1+ seconds ago
{ {
var newHash = subtitle.GetFastHashCode(string.Empty); var newHash = subtitle.GetFastHashCode(string.Empty);
if (newHash != _lastShowSubHash) if (newHash != _lastShowSubHash)
@ -124,7 +124,7 @@ namespace Nikse.SubtitleEdit.Logic
_lastShowSubHash = newHash; _lastShowSubHash = newHash;
} }
_lastShowSubTicks = DateTime.UtcNow.Ticks; _lastShowSubTicks = Stopwatch.GetTimestamp();
} }
} }

View File

@ -1,4 +1,4 @@
using System; using System.Diagnostics;
using Nikse.SubtitleEdit.Core.Common; using Nikse.SubtitleEdit.Core.Common;
namespace Nikse.SubtitleEdit.Logic namespace Nikse.SubtitleEdit.Logic
@ -14,10 +14,10 @@ namespace Nikse.SubtitleEdit.Logic
return; return;
} }
if (DateTime.UtcNow.Ticks - _lastCall > 10_000_000 * 60) // one minute if (Stopwatch.GetTimestamp() - _lastCall > 10_000_000 * 60) // one minute
{ {
NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS | NativeMethods.ES_SYSTEM_REQUIRED); NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS | NativeMethods.ES_SYSTEM_REQUIRED);
_lastCall = DateTime.UtcNow.Ticks; _lastCall = Stopwatch.GetTimestamp();
} }
} }
} }