mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-02 21:20:28 +12:00
Fixed watch folder sync context
This commit is contained in:
parent
5201b39bfa
commit
708ff2aa38
|
@ -705,7 +705,7 @@ public static void WaitWhileAsync(Func<bool> check, int interval, int timeout, A
|
|||
() =>
|
||||
{
|
||||
if (result) onSuccess();
|
||||
});
|
||||
}, false);
|
||||
}
|
||||
|
||||
public static bool IsFileLocked(string path)
|
||||
|
|
|
@ -30,14 +30,25 @@ namespace HelpersLib
|
|||
{
|
||||
public static class TaskEx
|
||||
{
|
||||
public static Task Run(Action action)
|
||||
public static Task Run(Action thread)
|
||||
{
|
||||
return Task.Factory.StartNew(action);
|
||||
return Task.Factory.StartNew(thread);
|
||||
}
|
||||
|
||||
public static Task Run(Action action, Action completed)
|
||||
public static Task Run(Action thread, Action completed, bool completedInFormThread = true)
|
||||
{
|
||||
return Run(action).ContinueWith(task => completed(), TaskScheduler.FromCurrentSynchronizationContext());
|
||||
TaskScheduler taskScheduler;
|
||||
|
||||
if (completedInFormThread)
|
||||
{
|
||||
taskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
|
||||
}
|
||||
else
|
||||
{
|
||||
taskScheduler = TaskScheduler.Current;
|
||||
}
|
||||
|
||||
return Run(thread).ContinueWith(task => completed(), taskScheduler);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -519,8 +519,7 @@ private static void uploaderConfigWatcher_Changed(object sender, FileSystemEvent
|
|||
{
|
||||
if (!uploaderConfigWatcherTimer.IsDuplicateEvent(e.FullPath))
|
||||
{
|
||||
SynchronizationContext context = SynchronizationContext.Current ?? new SynchronizationContext();
|
||||
Action onCompleted = () => context.Post(state => ReloadUploadersConfig(e.FullPath), null);
|
||||
Action onCompleted = () => ReloadUploadersConfig(e.FullPath);
|
||||
Helpers.WaitWhileAsync(() => Helpers.IsFileLocked(e.FullPath), 250, 5000, onCompleted, 1000);
|
||||
uploaderConfigWatcherTimer = new WatchFolderDuplicateEventTimer(e.FullPath);
|
||||
}
|
||||
|
@ -528,7 +527,7 @@ private static void uploaderConfigWatcher_Changed(object sender, FileSystemEvent
|
|||
|
||||
private static void ReloadUploadersConfig(string filePath)
|
||||
{
|
||||
UploadersConfig = UploadersLib.UploadersConfig.Load(filePath);
|
||||
UploadersConfig = UploadersConfig.Load(filePath);
|
||||
}
|
||||
|
||||
public static void UploadersConfigSaveAsync()
|
||||
|
|
Loading…
Reference in a new issue