diff --git a/HelpersLib/CLI/ExternalCLIManager.cs b/HelpersLib/CLI/ExternalCLIManager.cs index 673c60d86..e8170ba14 100644 --- a/HelpersLib/CLI/ExternalCLIManager.cs +++ b/HelpersLib/CLI/ExternalCLIManager.cs @@ -38,9 +38,6 @@ public abstract class ExternalCLIManager : IDisposable public event DataReceivedEventHandler OutputDataReceived; public event DataReceivedEventHandler ErrorDataReceived; - public StringBuilder Output { get; private set; } - public StringBuilder Errors { get; private set; } - private Process process = new Process(); public virtual int Open(string path, string args = null) @@ -49,9 +46,6 @@ public virtual int Open(string path, string args = null) if (File.Exists(path)) { - Output = new StringBuilder(); - Errors = new StringBuilder(); - ProcessStartInfo psi = new ProcessStartInfo(path); psi.UseShellExecute = false; psi.CreateNoWindow = true; @@ -78,8 +72,6 @@ private void cli_OutputDataReceived(object sender, DataReceivedEventArgs e) { if (e.Data != null) { - Output.AppendLine(e.Data); - if (OutputDataReceived != null) { OutputDataReceived(sender, e); @@ -91,8 +83,6 @@ private void cli_ErrorDataReceived(object sender, DataReceivedEventArgs e) { if (e.Data != null) { - Errors.AppendLine(e.Data); - if (ErrorDataReceived != null) { ErrorDataReceived(sender, e); diff --git a/HelpersLib/Forms/OutputBox.Designer.cs b/HelpersLib/Forms/OutputBox.Designer.cs new file mode 100644 index 000000000..91e467691 --- /dev/null +++ b/HelpersLib/Forms/OutputBox.Designer.cs @@ -0,0 +1,68 @@ +namespace HelpersLib +{ + partial class OutputBox + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.txtText = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // txtText + // + this.txtText.BackColor = System.Drawing.Color.Black; + this.txtText.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.txtText.Dock = System.Windows.Forms.DockStyle.Fill; + this.txtText.Font = new System.Drawing.Font("Lucida Console", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.txtText.ForeColor = System.Drawing.Color.White; + this.txtText.Location = new System.Drawing.Point(0, 0); + this.txtText.Multiline = true; + this.txtText.Name = "txtText"; + this.txtText.ScrollBars = System.Windows.Forms.ScrollBars.Both; + this.txtText.Size = new System.Drawing.Size(684, 562); + this.txtText.TabIndex = 0; + // + // OutputBox + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.Black; + this.ClientSize = new System.Drawing.Size(684, 562); + this.Controls.Add(this.txtText); + this.Name = "OutputBox"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "OutputBox"; + this.TopMost = true; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox txtText; + } +} \ No newline at end of file diff --git a/HelpersLib/Forms/OutputBox.cs b/HelpersLib/Forms/OutputBox.cs new file mode 100644 index 000000000..36c099676 --- /dev/null +++ b/HelpersLib/Forms/OutputBox.cs @@ -0,0 +1,48 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (C) 2007-2014 ShareX Developers + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace HelpersLib +{ + public partial class OutputBox : Form + { + public OutputBox(string text, string title) + { + InitializeComponent(); + Icon = ShareXResources.Icon; + Text = "ShareX - " + title; + txtText.Text = text; + txtText.SelectionStart = txtText.TextLength; + } + } +} \ No newline at end of file diff --git a/HelpersLib/Forms/OutputBox.resx b/HelpersLib/Forms/OutputBox.resx new file mode 100644 index 000000000..7080a7d11 --- /dev/null +++ b/HelpersLib/Forms/OutputBox.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HelpersLib/Helpers/Helpers.cs b/HelpersLib/Helpers/Helpers.cs index 2025464b4..b4b2b31a9 100644 --- a/HelpersLib/Helpers/Helpers.cs +++ b/HelpersLib/Helpers/Helpers.cs @@ -471,7 +471,7 @@ public static void OpenURL(string url) { if (!string.IsNullOrEmpty(url)) { - ThreadPool.QueueUserWorkItem(state => + Task.Run(() => { try { @@ -606,7 +606,7 @@ public static object Clone(object obj) public static void PlaySoundAsync(Stream stream) { - ThreadPool.QueueUserWorkItem(state => + Task.Run(() => { using (stream) using (SoundPlayer soundPlayer = new SoundPlayer(stream)) diff --git a/HelpersLib/Helpers/ImageHelpers.cs b/HelpersLib/Helpers/ImageHelpers.cs index 0fe7dcfbc..c0345f776 100644 --- a/HelpersLib/Helpers/ImageHelpers.cs +++ b/HelpersLib/Helpers/ImageHelpers.cs @@ -64,7 +64,6 @@ using System.Reflection; using System.Runtime.InteropServices; using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace HelpersLib diff --git a/HelpersLib/HelpersLib.csproj b/HelpersLib/HelpersLib.csproj index 55c55b7d2..0461b14a3 100644 --- a/HelpersLib/HelpersLib.csproj +++ b/HelpersLib/HelpersLib.csproj @@ -51,10 +51,6 @@ Off - - False - ..\packages\AsyncBridge.Net35.0.2.0\lib\net35-Client\AsyncBridge.Net35.dll - ..\packages\QrCode.Net.0.4.0.0\lib\net35\Gma.QrCodeNet.Encoding.dll @@ -70,10 +66,6 @@ - - False - ..\packages\TaskParallelLibrary.1.0.2856.0\lib\Net35\System.Threading.dll - 3.5 @@ -95,6 +87,12 @@ + + Form + + + OutputBox.cs + Form @@ -117,6 +115,7 @@ + @@ -335,6 +334,9 @@ MonitorTestForm.cs + + OutputBox.cs + QRCodeForm.cs diff --git a/HelpersLib/SettingsBase.cs b/HelpersLib/SettingsBase.cs index dac85a5ce..1fa12b0f8 100644 --- a/HelpersLib/SettingsBase.cs +++ b/HelpersLib/SettingsBase.cs @@ -66,7 +66,7 @@ private void Save() public void SaveAsync(string filePath) { - ThreadPool.QueueUserWorkItem(state => Save(filePath)); + Task.Run(() => Save(filePath)); } private void SaveAsync() diff --git a/HelpersLib/Task.cs b/HelpersLib/Task.cs new file mode 100644 index 000000000..c2fb5d0de --- /dev/null +++ b/HelpersLib/Task.cs @@ -0,0 +1,41 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (C) 2007-2014 ShareX Developers + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; + +namespace HelpersLib +{ + public static class Task + { + public static void Run(Action action) + { + ThreadPool.QueueUserWorkItem(state => action()); + } + } +} \ No newline at end of file diff --git a/HelpersLib/packages.config b/HelpersLib/packages.config index 3ea07c716..dffc5bf66 100644 --- a/HelpersLib/packages.config +++ b/HelpersLib/packages.config @@ -1,7 +1,5 @@  - - \ No newline at end of file diff --git a/HistoryLib/HistoryLib.csproj b/HistoryLib/HistoryLib.csproj index 582b41227..cc442ed1e 100644 --- a/HistoryLib/HistoryLib.csproj +++ b/HistoryLib/HistoryLib.csproj @@ -45,20 +45,12 @@ OnBuildSuccess - - False - ..\packages\AsyncBridge.Net35.0.2.0\lib\net35-Client\AsyncBridge.Net35.dll - False ..\packages\ImageListView.11.0.1\lib\net35\ImageListView.dll - - False - ..\packages\TaskParallelLibrary.1.0.2856.0\lib\Net35\System.Threading.dll - diff --git a/HistoryLib/HistoryManager.cs b/HistoryLib/HistoryManager.cs index b535c8250..7644dd0d9 100644 --- a/HistoryLib/HistoryManager.cs +++ b/HistoryLib/HistoryManager.cs @@ -73,13 +73,11 @@ public List GetHistoryItems() public static void AddHistoryItemAsync(string historyPath, HistoryItem historyItem) { - WaitCallback thread = state => + Task.Run(() => { HistoryManager history = new HistoryManager(historyPath); history.AppendHistoryItem(historyItem); - }; - - ThreadPool.QueueUserWorkItem(thread); + }); } } } \ No newline at end of file diff --git a/HistoryLib/packages.config b/HistoryLib/packages.config index 7fef42474..38952d71b 100644 --- a/HistoryLib/packages.config +++ b/HistoryLib/packages.config @@ -1,6 +1,4 @@  - - \ No newline at end of file diff --git a/ScreenCaptureLib/ScreenCaptureLib.csproj b/ScreenCaptureLib/ScreenCaptureLib.csproj index 8ec987120..ea41d408a 100644 --- a/ScreenCaptureLib/ScreenCaptureLib.csproj +++ b/ScreenCaptureLib/ScreenCaptureLib.csproj @@ -41,10 +41,6 @@ Off - - False - ..\packages\AsyncBridge.Net35.0.2.0\lib\net35-Client\AsyncBridge.Net35.dll - ..\packages\SevenZipSharp.0.64\lib\SevenZipSharp.dll diff --git a/ScreenCaptureLib/Screencast/FFmpegHelper.cs b/ScreenCaptureLib/Screencast/FFmpegHelper.cs index 1659eeeb9..a42870282 100644 --- a/ScreenCaptureLib/Screencast/FFmpegHelper.cs +++ b/ScreenCaptureLib/Screencast/FFmpegHelper.cs @@ -42,22 +42,36 @@ public class FFmpegHelper : ExternalCLIManager public static readonly int libmp3lame_qscale_end = 9; public static readonly string GDIgrab = "GDI grab"; + public StringBuilder Output { get; private set; } public ScreencastOptions Options { get; private set; } public FFmpegHelper(ScreencastOptions options) { + Output = new StringBuilder(); + OutputDataReceived += FFmpegHelper_DataReceived; + ErrorDataReceived += FFmpegHelper_DataReceived; Options = options; Helpers.CreateDirectoryIfNotExist(Options.OutputPath); } + private void FFmpegHelper_DataReceived(object sender, DataReceivedEventArgs e) + { + lock (this) + { + if (!string.IsNullOrEmpty(e.Data)) + { + Output.AppendLine(e.Data); + } + } + } + public bool Record() { int errorCode = Open(Options.FFmpeg.CLIPath, Options.GetFFmpegArgs()); bool result = errorCode == 0; if (Options.FFmpeg.ShowError && !result) { - string text = string.Join("\r\n", Errors.ToString().Lines().Where(x => !string.IsNullOrEmpty(x)).TakeLast(10).ToArray()); - MessageBox.Show(text, "ShareX - FFmpeg error", MessageBoxButtons.OK, MessageBoxIcon.Error); + new OutputBox(Output.ToString(), "FFmpeg error").ShowDialog(); } return result; } @@ -133,7 +147,7 @@ public DirectShowDevices GetDirectShowDevices() { string arg = "-list_devices true -f dshow -i dummy"; Open(Options.FFmpeg.CLIPath, arg); - string output = Errors.ToString(); + string output = Output.ToString(); string[] lines = output.Lines(); bool isVideo = true; Regex regex = new Regex("\\[dshow @ \\w+\\] \"(.+)\"", RegexOptions.Compiled | RegexOptions.CultureInvariant); diff --git a/ScreenCaptureLib/Screencast/ImageCache.cs b/ScreenCaptureLib/Screencast/ImageCache.cs index 30220738c..d00ab3b67 100644 --- a/ScreenCaptureLib/Screencast/ImageCache.cs +++ b/ScreenCaptureLib/Screencast/ImageCache.cs @@ -30,6 +30,7 @@ using System.Drawing; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace ScreenCaptureLib @@ -39,7 +40,7 @@ public abstract class ImageCache : IDisposable public bool IsWorking { get; protected set; } public ScreencastOptions Options { get; set; } - protected Task task; + protected Thread task; protected BlockingCollection imageQueue; public ImageCache() @@ -63,7 +64,7 @@ protected virtual void StartConsumerThread() { IsWorking = true; - task = TaskEx.Run(() => + task = new Thread(() => { try { @@ -95,6 +96,8 @@ protected virtual void StartConsumerThread() IsWorking = false; } }); + + task.Start(); } } @@ -105,7 +108,7 @@ public void Finish() if (IsWorking) { imageQueue.CompleteAdding(); - task.Wait(); + task.Join(); } Dispose(); diff --git a/ScreenCaptureLib/packages.config b/ScreenCaptureLib/packages.config index 9d273bdb5..88008ecbd 100644 --- a/ScreenCaptureLib/packages.config +++ b/ScreenCaptureLib/packages.config @@ -1,6 +1,5 @@  - \ No newline at end of file diff --git a/ShareX/Forms/MainForm_Capture.cs b/ShareX/Forms/MainForm_Capture.cs index a5ae49c86..817127cde 100644 --- a/ShareX/Forms/MainForm_Capture.cs +++ b/ShareX/Forms/MainForm_Capture.cs @@ -32,7 +32,6 @@ using System.Diagnostics; using System.Drawing; using System.Threading; -using System.Threading.Tasks; using System.Windows.Forms; namespace ShareX @@ -43,7 +42,7 @@ public partial class MainForm private void InitHotkeys() { - ThreadPool.QueueUserWorkItem(state => + Task.Run(() => { if (Program.HotkeysConfig == null) { @@ -467,54 +466,61 @@ private void CaptureLastRegion(TaskSettings taskSettings, bool autoHideForm = tr } } - private async void PrepareCaptureMenuAsync(ToolStripMenuItem tsmiWindow, EventHandler handlerWindow, ToolStripMenuItem tsmiMonitor, EventHandler handlerMonitor) + private void PrepareCaptureMenuAsync(ToolStripMenuItem tsmiWindow, EventHandler handlerWindow, ToolStripMenuItem tsmiMonitor, EventHandler handlerMonitor) { tsmiWindow.DropDownItems.Clear(); WindowsList windowsList = new WindowsList(); - List windows = await TaskEx.Run(() => windowsList.GetVisibleWindowsList()); + List windows = null; - if (windows != null) + Helpers.AsyncJob(() => { - foreach (WindowInfo window in windows) + windows = windowsList.GetVisibleWindowsList(); + }, + () => + { + if (windows != null) { - try + foreach (WindowInfo window in windows) { - string title = window.Text.Truncate(50); - ToolStripItem tsi = tsmiWindow.DropDownItems.Add(title); - tsi.Tag = window; - tsi.Click += handlerWindow; - - using (Icon icon = window.Icon) + try { - if (icon != null && icon.Width > 0 && icon.Height > 0) + string title = window.Text.Truncate(50); + ToolStripItem tsi = tsmiWindow.DropDownItems.Add(title); + tsi.Tag = window; + tsi.Click += handlerWindow; + + using (Icon icon = window.Icon) { - tsi.Image = icon.ToBitmap(); + if (icon != null && icon.Width > 0 && icon.Height > 0) + { + tsi.Image = icon.ToBitmap(); + } } } - } - catch (Exception e) - { - DebugHelper.WriteException(e); + catch (Exception e) + { + DebugHelper.WriteException(e); + } } } - } - tsmiMonitor.DropDownItems.Clear(); + tsmiMonitor.DropDownItems.Clear(); - Screen[] screens = Screen.AllScreens; + Screen[] screens = Screen.AllScreens; - for (int i = 0; i < screens.Length; i++) - { - Screen screen = screens[i]; - string text = string.Format("{0}. {1}x{2}", i + 1, screen.Bounds.Width, screen.Bounds.Height); - ToolStripItem tsi = tsmiMonitor.DropDownItems.Add(text); - tsi.Tag = screen.Bounds; - tsi.Click += handlerMonitor; - } + for (int i = 0; i < screens.Length; i++) + { + Screen screen = screens[i]; + string text = string.Format("{0}. {1}x{2}", i + 1, screen.Bounds.Width, screen.Bounds.Height); + ToolStripItem tsi = tsmiMonitor.DropDownItems.Add(text); + tsi.Tag = screen.Bounds; + tsi.Click += handlerMonitor; + } - tsmiWindow.Invalidate(); - tsmiMonitor.Invalidate(); + tsmiWindow.Invalidate(); + tsmiMonitor.Invalidate(); + }); } #region Menu events diff --git a/ShareX/Forms/ScreenRecordForm.cs b/ShareX/Forms/ScreenRecordForm.cs index 175c831db..fb91a3f74 100644 --- a/ShareX/Forms/ScreenRecordForm.cs +++ b/ShareX/Forms/ScreenRecordForm.cs @@ -30,7 +30,6 @@ using System.Drawing; using System.IO; using System.Threading; -using System.Threading.Tasks; using System.Windows.Forms; using UploadersLib; @@ -81,7 +80,7 @@ private void SelectRegion() } } - public async void StartRecording(TaskSettings TaskSettings) + public void StartRecording(TaskSettings TaskSettings) { if (TaskSettings.CaptureSettings.RunScreencastCLI) { @@ -132,92 +131,90 @@ public async void StartRecording(TaskSettings TaskSettings) string path = ""; - try - { - using (ScreenRegionManager screenRegionManager = new ScreenRegionManager()) - { - screenRegionManager.Start(captureRectangle); + ScreenRegionManager screenRegionManager = new ScreenRegionManager(); + screenRegionManager.Start(captureRectangle); - await TaskEx.Run(() => + Helpers.AsyncJob(() => + { + if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.AVI) + { + path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, "avi")); + } + else if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.FFmpeg) + { + path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, TaskSettings.CaptureSettings.FFmpegOptions.Extension)); + } + else + { + path = Program.ScreenRecorderCacheFilePath; + } + + ScreencastOptions options = new ScreencastOptions() + { + CaptureArea = captureRectangle, + GIFFPS = TaskSettings.CaptureSettings.GIFFPS, + ScreenRecordFPS = TaskSettings.CaptureSettings.ScreenRecordFPS, + OutputPath = path, + Duration = TaskSettings.CaptureSettings.ScreenRecordFixedDuration ? TaskSettings.CaptureSettings.ScreenRecordDuration : 0, + AVI = TaskSettings.CaptureSettings.AVIOptions, + FFmpeg = TaskSettings.CaptureSettings.FFmpegOptions, + DrawCursor = TaskSettings.CaptureSettings.ShowCursor + }; + + screenRecorder = new ScreenRecorder(options, captureRectangle, TaskSettings.CaptureSettings.ScreenRecordOutput); + + int delay = (int)(TaskSettings.CaptureSettings.ScreenRecordStartDelay * 1000); + + if (delay > 0) + { + Thread.Sleep(delay); + } + + this.InvokeSafe(() => + { + screenRegionManager.ChangeColor(Color.FromArgb(0, 255, 0)); + TrayIcon.Icon = Resources.control_record.ToIcon(); + }); + + screenRecorder.StartRecording(); + + if (screenRegionManager != null) + { + this.InvokeSafe(() => screenRegionManager.Dispose()); + } + + if (screenRecorder != null) + { + TrayIcon.Icon = Resources.camcorder_pencil.ToIcon(); + + string sourceFilePath = path; + + if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.GIF) { - if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.AVI) + if (TaskSettings.CaptureSettings.RunScreencastCLI) { - path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, "avi")); - } - else if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.FFmpeg) - { - path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, TaskSettings.CaptureSettings.FFmpegOptions.Extension)); + sourceFilePath = Path.ChangeExtension(Program.ScreenRecorderCacheFilePath, "gif"); } else { - path = Program.ScreenRecorderCacheFilePath; + sourceFilePath = path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, "gif")); } + screenRecorder.SaveAsGIF(sourceFilePath, TaskSettings.ImageSettings.ImageGIFQuality); + } - ScreencastOptions options = new ScreencastOptions() - { - CaptureArea = captureRectangle, - GIFFPS = TaskSettings.CaptureSettings.GIFFPS, - ScreenRecordFPS = TaskSettings.CaptureSettings.ScreenRecordFPS, - OutputPath = path, - Duration = TaskSettings.CaptureSettings.ScreenRecordFixedDuration ? TaskSettings.CaptureSettings.ScreenRecordDuration : 0, - AVI = TaskSettings.CaptureSettings.AVIOptions, - FFmpeg = TaskSettings.CaptureSettings.FFmpegOptions, - DrawCursor = TaskSettings.CaptureSettings.ShowCursor - }; - - screenRecorder = new ScreenRecorder(options, captureRectangle, TaskSettings.CaptureSettings.ScreenRecordOutput); - - int delay = (int)(TaskSettings.CaptureSettings.ScreenRecordStartDelay * 1000); - - if (delay > 0) - { - Thread.Sleep(delay); - } - - screenRegionManager.ChangeColor(); - - this.InvokeSafe(() => TrayIcon.Icon = Resources.control_record.ToIcon()); - - screenRecorder.StartRecording(); - }); - } - - if (screenRecorder != null) - { - TrayIcon.Icon = Resources.camcorder__pencil.ToIcon(); - - await TaskEx.Run(() => + if (TaskSettings.CaptureSettings.RunScreencastCLI) { - string sourceFilePath = path; - - if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.GIF) - { - if (TaskSettings.CaptureSettings.RunScreencastCLI) - { - sourceFilePath = Path.ChangeExtension(Program.ScreenRecorderCacheFilePath, "gif"); - } - else - { - sourceFilePath = path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, "gif")); - } - screenRecorder.SaveAsGIF(sourceFilePath, TaskSettings.ImageSettings.ImageGIFQuality); - } - - if (TaskSettings.CaptureSettings.RunScreencastCLI) - { - VideoEncoder encoder = Program.Settings.VideoEncoders[TaskSettings.CaptureSettings.VideoEncoderSelected]; - path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, encoder.OutputExtension)); - screenRecorder.EncodeUsingCommandLine(encoder, sourceFilePath, path); - } - }); + VideoEncoder encoder = Program.Settings.VideoEncoders[TaskSettings.CaptureSettings.VideoEncoderSelected]; + path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, encoder.OutputExtension)); + screenRecorder.EncodeUsingCommandLine(encoder, sourceFilePath, path); + } } - } - finally + }, + () => { if (screenRecorder != null) { - if (TaskSettings.CaptureSettings.RunScreencastCLI && - !string.IsNullOrEmpty(screenRecorder.CachePath) && File.Exists(screenRecorder.CachePath)) + if (TaskSettings.CaptureSettings.RunScreencastCLI && !string.IsNullOrEmpty(screenRecorder.CachePath) && File.Exists(screenRecorder.CachePath)) { File.Delete(screenRecorder.CachePath); } @@ -230,26 +227,26 @@ public async void StartRecording(TaskSettings TaskSettings) { TrayIcon.Visible = false; } - } - if (!string.IsNullOrEmpty(path) && File.Exists(path)) - { - if (TaskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.UploadImageToHost)) + if (!string.IsNullOrEmpty(path) && File.Exists(path)) { - UploadManager.UploadFile(path, TaskSettings); - } - else - { - if (TaskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.CopyFilePathToClipboard)) + if (TaskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.UploadImageToHost)) { - ClipboardHelpers.CopyText(path); + UploadManager.UploadFile(path, TaskSettings); } + else + { + if (TaskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.CopyFilePathToClipboard)) + { + ClipboardHelpers.CopyText(path); + } - TaskHelpers.ShowResultNotifications(path, TaskSettings, path); + TaskHelpers.ShowResultNotifications(path, TaskSettings, path); + } } - } - IsRecording = false; + IsRecording = false; + }); } private void DownloaderForm_InstallRequested(string filePath) diff --git a/ShareX/Forms/UploadTestForm.cs b/ShareX/Forms/UploadTestForm.cs index 54cd4ae89..760354ac1 100644 --- a/ShareX/Forms/UploadTestForm.cs +++ b/ShareX/Forms/UploadTestForm.cs @@ -313,7 +313,7 @@ private void openURLToolStripMenuItem_Click(object sender, EventArgs e) if (task != null && task.Info != null && task.Info.Result != null && !string.IsNullOrEmpty(task.Info.Result.ToString())) { - ThreadPool.QueueUserWorkItem(x => Process.Start(task.Info.Result.ToString())); + Task.Run(() => Process.Start(task.Info.Result.ToString())); } } } diff --git a/ShareX/Program.cs b/ShareX/Program.cs index cc865728c..2171cb5f7 100644 --- a/ShareX/Program.cs +++ b/ShareX/Program.cs @@ -32,7 +32,6 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading; -using System.Threading.Tasks; using System.Windows.Forms; using UploadersLib; @@ -317,7 +316,7 @@ private static void Run(string[] args) SettingsResetEvent = new ManualResetEvent(false); UploaderSettingsResetEvent = new ManualResetEvent(false); HotkeySettingsResetEvent = new ManualResetEvent(false); - ThreadPool.QueueUserWorkItem(state => LoadSettings()); + Task.Run(() => LoadSettings()); DebugHelper.WriteLine("MainForm init started"); MainForm = new MainForm(); @@ -532,11 +531,18 @@ private static void ReloadUploadersConfig(string filePath) UploadersConfig = UploadersLib.UploadersConfig.Load(filePath); } - public async static void UploadersConfigSaveAsync() + public static void UploadersConfigSaveAsync() { if (uploaderConfigWatcher != null) uploaderConfigWatcher.EnableRaisingEvents = false; - await TaskEx.Run(() => UploadersConfig.Save(Program.UploadersConfigFilePath)); - if (uploaderConfigWatcher != null) uploaderConfigWatcher.EnableRaisingEvents = true; + + Helpers.AsyncJob(() => + { + UploadersConfig.Save(Program.UploadersConfigFilePath); + }, + () => + { + if (uploaderConfigWatcher != null) uploaderConfigWatcher.EnableRaisingEvents = true; + }); } } } \ No newline at end of file diff --git a/ShareX/Properties/Resources.Designer.cs b/ShareX/Properties/Resources.Designer.cs index 8f47502c9..9c58dfd06 100644 --- a/ShareX/Properties/Resources.Designer.cs +++ b/ShareX/Properties/Resources.Designer.cs @@ -213,9 +213,9 @@ public class Resources { /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// - public static System.Drawing.Bitmap camcorder__pencil { + public static System.Drawing.Bitmap camcorder_image { get { - object obj = ResourceManager.GetObject("camcorder__pencil", resourceCulture); + object obj = ResourceManager.GetObject("camcorder_image", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } } @@ -223,9 +223,9 @@ public class Resources { /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// - public static System.Drawing.Bitmap camcorder_image { + public static System.Drawing.Bitmap camcorder_pencil { get { - object obj = ResourceManager.GetObject("camcorder_image", resourceCulture); + object obj = ResourceManager.GetObject("camcorder_pencil", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } } diff --git a/ShareX/Properties/Resources.resx b/ShareX/Properties/Resources.resx index 24000fe56..eb932971e 100644 --- a/ShareX/Properties/Resources.resx +++ b/ShareX/Properties/Resources.resx @@ -133,7 +133,7 @@ ..\Resources\hammer--pencil.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - + ..\Resources\camcorder--pencil.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/ShareX/ScreenRegionManager.cs b/ShareX/ScreenRegionManager.cs index 958fade58..aab33caad 100644 --- a/ShareX/ScreenRegionManager.cs +++ b/ShareX/ScreenRegionManager.cs @@ -42,11 +42,11 @@ public void Start(Rectangle captureRectangle) } } - public void ChangeColor() + public void ChangeColor(Color color) { if (regionForm != null) { - regionForm.InvokeSafe(() => regionForm.ChangeColor(Color.FromArgb(0, 255, 0))); + regionForm.ChangeColor(color); } } diff --git a/ShareX/ShareX.csproj b/ShareX/ShareX.csproj index 409d6c725..da86effde 100644 --- a/ShareX/ShareX.csproj +++ b/ShareX/ShareX.csproj @@ -66,9 +66,6 @@ app.manifest - - ..\packages\AsyncBridge.Net35.0.2.0\lib\net35-Client\AsyncBridge.Net35.dll - False ..\packages\MegaApiClient.1.0.4\lib\MegaApiClient.dll @@ -83,9 +80,6 @@ - - ..\packages\TaskParallelLibrary.1.0.2856.0\lib\Net35\System.Threading.dll - 3.5 diff --git a/ShareX/packages.config b/ShareX/packages.config index 61337a8fd..70b1d8080 100644 --- a/ShareX/packages.config +++ b/ShareX/packages.config @@ -1,7 +1,5 @@  - - \ No newline at end of file diff --git a/UploadersLib/FTPClient/FTPClientForm.cs b/UploadersLib/FTPClient/FTPClientForm.cs index 4dde9a74b..013ee769d 100644 --- a/UploadersLib/FTPClient/FTPClientForm.cs +++ b/UploadersLib/FTPClient/FTPClientForm.cs @@ -554,7 +554,7 @@ private void openURLToolStripMenuItem_Click(object sender, EventArgs e) FtpItem file = lvFTPList.SelectedItems[0].Tag as FtpItem; if (file != null && file.ItemType == FtpItemType.File) { - ThreadPool.QueueUserWorkItem(x => Process.Start(Account.GetUriPath("@" + file.FullPath))); + Task.Run(() => Process.Start(Account.GetUriPath("@" + file.FullPath))); } } } diff --git a/UploadersLib/FileUploaders/FTPUploader.cs b/UploadersLib/FileUploaders/FTPUploader.cs index 4210e01a2..ce599cf25 100644 --- a/UploadersLib/FileUploaders/FTPUploader.cs +++ b/UploadersLib/FileUploaders/FTPUploader.cs @@ -76,7 +76,7 @@ public override void StopUpload() { stopUpload = true; - ThreadPool.QueueUserWorkItem(state => ftpClient.StopUpload()); + Task.Run(() => ftpClient.StopUpload()); } } diff --git a/UploadersLib/GUI/DropboxFilesForm.cs b/UploadersLib/GUI/DropboxFilesForm.cs index ee4d1575f..3da7cb347 100644 --- a/UploadersLib/GUI/DropboxFilesForm.cs +++ b/UploadersLib/GUI/DropboxFilesForm.cs @@ -28,7 +28,6 @@ using System.ComponentModel; using System.IO; using System.Linq; -using System.Threading.Tasks; using System.Windows.Forms; using UploadersLib.FileUploaders; using UploadersLib.HelperClasses; @@ -60,45 +59,52 @@ public DropboxFilesForm(OAuthInfo oauth, string path, DropboxAccountInfo account } } - public async void OpenDirectory(string path) + public void OpenDirectory(string path) { lvDropboxFiles.Items.Clear(); - DropboxContentInfo contentInfo = await TaskEx.Run(() => dropbox.GetMetadata(path, true)); + DropboxContentInfo contentInfo = null; - if (contentInfo != null) + Helpers.AsyncJob(() => { - lvDropboxFiles.Tag = contentInfo; - - ListViewItem lvi = GetParentFolder(contentInfo.Path); - - if (lvi != null) + contentInfo = dropbox.GetMetadata(path, true); + }, + () => + { + if (contentInfo != null) { - lvDropboxFiles.Items.Add(lvi); - } + lvDropboxFiles.Tag = contentInfo; - foreach (DropboxContentInfo content in contentInfo.Contents.OrderBy(x => !x.Is_dir)) - { - string filename = Path.GetFileName(content.Path); - lvi = new ListViewItem(filename); - lvi.SubItems.Add(content.Is_dir ? "" : content.Size); - DateTime modified; - if (DateTime.TryParse(content.Modified, out modified)) + ListViewItem lvi = GetParentFolder(contentInfo.Path); + + if (lvi != null) { - lvi.SubItems.Add(modified.ToString()); + lvDropboxFiles.Items.Add(lvi); } - lvi.ImageKey = ilm.AddImage(content.Icon); - lvi.Tag = content; - lvDropboxFiles.Items.Add(lvi); - } - CurrentFolderPath = contentInfo.Path.Trim('/'); - Text = "Dropbox - " + CurrentFolderPath; - } - else - { - MessageBox.Show("Path not exist: " + path, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } + foreach (DropboxContentInfo content in contentInfo.Contents.OrderBy(x => !x.Is_dir)) + { + string filename = Path.GetFileName(content.Path); + lvi = new ListViewItem(filename); + lvi.SubItems.Add(content.Is_dir ? "" : content.Size); + DateTime modified; + if (DateTime.TryParse(content.Modified, out modified)) + { + lvi.SubItems.Add(modified.ToString()); + } + lvi.ImageKey = ilm.AddImage(content.Icon); + lvi.Tag = content; + lvDropboxFiles.Items.Add(lvi); + } + + CurrentFolderPath = contentInfo.Path.Trim('/'); + Text = "Dropbox - " + CurrentFolderPath; + } + else + { + MessageBox.Show("Path not exist: " + path, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + }); } public void RefreshDirectory() diff --git a/UploadersLib/GUI/UploadersConfigFormHelper.cs b/UploadersLib/GUI/UploadersConfigFormHelper.cs index 0c28e8b58..a70e32ded 100644 --- a/UploadersLib/GUI/UploadersConfigFormHelper.cs +++ b/UploadersLib/GUI/UploadersConfigFormHelper.cs @@ -33,7 +33,6 @@ using System.Net.NetworkInformation; using System.Text; using System.Threading; -using System.Threading.Tasks; using System.Windows.Forms; using UploadersLib.FileUploaders; using UploadersLib.Forms; @@ -1500,13 +1499,13 @@ private CustomUploaderItem GetCustomUploaderFromFields() return item; } - private async void TestCustomUploader(CustomUploaderType type, CustomUploaderItem item) + private void TestCustomUploader(CustomUploaderType type, CustomUploaderItem item) { UploadResult result = null; txtCustomUploaderLog.ResetText(); - await TaskEx.Run(() => + Helpers.AsyncJob(() => { try { @@ -1545,31 +1544,33 @@ private async void TestCustomUploader(CustomUploaderType type, CustomUploaderIte result = new UploadResult(); result.Errors.Add(e.Message); } - }); - - if (result != null) + }, + () => { - if ((type != CustomUploaderType.URL && !string.IsNullOrEmpty(result.URL)) || (type == CustomUploaderType.URL && !string.IsNullOrEmpty(result.ShortenedURL))) + if (result != null) { - txtCustomUploaderLog.AppendText("URL: " + result + Environment.NewLine); - } - else if (result.IsError) - { - txtCustomUploaderLog.AppendText("Error: " + result.ErrorsToString() + Environment.NewLine); - } - else - { - txtCustomUploaderLog.AppendText("Error: Result is empty." + Environment.NewLine); + if ((type != CustomUploaderType.URL && !string.IsNullOrEmpty(result.URL)) || (type == CustomUploaderType.URL && !string.IsNullOrEmpty(result.ShortenedURL))) + { + txtCustomUploaderLog.AppendText("URL: " + result + Environment.NewLine); + } + else if (result.IsError) + { + txtCustomUploaderLog.AppendText("Error: " + result.ErrorsToString() + Environment.NewLine); + } + else + { + txtCustomUploaderLog.AppendText("Error: Result is empty." + Environment.NewLine); + } + + txtCustomUploaderLog.ScrollToCaret(); + + btnCustomUploaderShowLastResponse.Tag = result.Response; + btnCustomUploaderShowLastResponse.Enabled = !string.IsNullOrEmpty(result.Response); } - txtCustomUploaderLog.ScrollToCaret(); - - btnCustomUploaderShowLastResponse.Tag = result.Response; - btnCustomUploaderShowLastResponse.Enabled = !string.IsNullOrEmpty(result.Response); - } - - btnCustomUploaderImageUploaderTest.Enabled = btnCustomUploaderTextUploaderTest.Enabled = - btnCustomUploaderFileUploaderTest.Enabled = btnCustomUploaderURLShortenerTest.Enabled = true; + btnCustomUploaderImageUploaderTest.Enabled = btnCustomUploaderTextUploaderTest.Enabled = + btnCustomUploaderFileUploaderTest.Enabled = btnCustomUploaderURLShortenerTest.Enabled = true; + }); } #endregion Custom uploader diff --git a/UploadersLib/UploadersLib.csproj b/UploadersLib/UploadersLib.csproj index deccf8bd8..b1045fd93 100644 --- a/UploadersLib/UploadersLib.csproj +++ b/UploadersLib/UploadersLib.csproj @@ -99,12 +99,6 @@ 3.5 - - ..\packages\AsyncBridge.Net35.0.2.0\lib\net35-Client\AsyncBridge.Net35.dll - - - ..\packages\TaskParallelLibrary.1.0.2856.0\lib\Net35\System.Threading.dll - diff --git a/UploadersLib/packages.config b/UploadersLib/packages.config index d82f4e8f1..31fc410f2 100644 --- a/UploadersLib/packages.config +++ b/UploadersLib/packages.config @@ -1,8 +1,6 @@  - - \ No newline at end of file