Changeset 17068 for stable/HeuristicLab.Common/3.3/Content
- Timestamp:
- 07/04/19 15:26:27 (5 years ago)
- Location:
- stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Common/3.3/Content/ContentManager.cs
r15584 r17068 21 21 22 22 using System; 23 using System.Threading; 23 24 24 25 namespace HeuristicLab.Common { … … 43 44 if (instance == null) throw new InvalidOperationException("ContentManager is not initialized."); 44 45 var func = new Func<string, IStorableContent>(instance.LoadContent); 45 func.BeginInvoke(filename, delegate (IAsyncResult result) {46 func.BeginInvoke(filename, delegate (IAsyncResult result) { 46 47 Exception error = null; 47 48 IStorableContent content = null; … … 49 50 content = func.EndInvoke(result); 50 51 content.Filename = filename; 51 } 52 catch (Exception ex) { 52 } catch (Exception ex) { 53 53 error = ex; 54 54 } … … 58 58 protected abstract IStorableContent LoadContent(string filename); 59 59 60 public static void Save(IStorableContent content, string filename, bool compressed ) {60 public static void Save(IStorableContent content, string filename, bool compressed, CancellationToken cancellationToken = default(CancellationToken)) { 61 61 if (instance == null) throw new InvalidOperationException("ContentManager is not initialized."); 62 instance.SaveContent(content, filename, compressed );62 instance.SaveContent(content, filename, compressed, cancellationToken); 63 63 content.Filename = filename; 64 64 } 65 public static void SaveAsync(IStorableContent content, string filename, bool compressed, Action<IStorableContent, Exception> savingCompletedCallback ) {65 public static void SaveAsync(IStorableContent content, string filename, bool compressed, Action<IStorableContent, Exception> savingCompletedCallback, CancellationToken cancellationToken = default(CancellationToken)) { 66 66 if (instance == null) throw new InvalidOperationException("ContentManager is not initialized."); 67 var action = new Action<IStorableContent, string, bool >(instance.SaveContent);68 action.BeginInvoke(content, filename, compressed, delegate(IAsyncResult result) {67 var action = new Action<IStorableContent, string, bool, CancellationToken>(instance.SaveContent); 68 action.BeginInvoke(content, filename, compressed, cancellationToken, delegate (IAsyncResult result) { 69 69 Exception error = null; 70 70 try { 71 71 action.EndInvoke(result); 72 72 content.Filename = filename; 73 } 74 catch (Exception ex) { 73 } catch (Exception ex) { 75 74 error = ex; 76 75 } … … 79 78 80 79 } 81 protected abstract void SaveContent(IStorableContent content, string filename, bool compressed );80 protected abstract void SaveContent(IStorableContent content, string filename, bool compressed, CancellationToken cancellationToken); 82 81 } 83 82 }
Note: See TracChangeset
for help on using the changeset viewer.