Fixed watch folder sync context

This commit is contained in:
Jaex 2014-06-01 09:59:40 +03:00
parent 5201b39bfa
commit 708ff2aa38
3 changed files with 18 additions and 8 deletions

View file

@ -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)

View file

@ -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);
}
}
}

View file

@ -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()